HardwareTimer Timer1(TIM1); // the setup function runs once when you press reset or power the board uint8_t sw = LOW; int sensorPin = A6; // select the input pin for the potentiometer int biasPin = A12; int audioOut = A13; int sensorValue = 0; // variable to store the value coming from the sensor bool Sendflg = true; int sendTimingCnt=0; void sendDebugdat(){ sw ^=1; digitalWrite(LED_GREEN, sw); printf("%d\n",sensorValue); } void audioreader() { sensorValue = analogRead(sensorPin);//多分12bitで読み取る sendTimingCnt++; analogWrite(audioOut,sensorValue*5); } void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(LED_GREEN, OUTPUT); pinMode(audioOut, OUTPUT); pinMode(biasPin, OUTPUT); analogWriteResolution(12);//analogwriteを12bit(MAX4095)で利用できるように設定 analogReadResolution(12); analogWrite(biasPin,2482); Timer1.pause(); // タイマー停止 //Timer1.setOverflow(4000,HERTZ_FORMAT); // 4000Hzで呼び出し Timer1.setOverflow(48000,HERTZ_FORMAT); // 48000Hzで呼び出し Timer1.attachInterrupt( // 割り込みハンドラの登録 audioreader // 呼び出す関数 ); Timer1.setCount(0); // カウンタを0に設定 Timer1.refresh(); // タイマ更新 Timer1.resume(); // タイマースタート tone(PB4,200); analogWrite(biasPin,2482); } // the loop function runs over and over again forever void loop() { if(sendTimingCnt >= 2000){ sendDebugdat(); sendTimingCnt=0; } }