STM32F767_ANC_IMC.ino 1.58 KB
Newer Older
杉下大河's avatar
杉下大河 committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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;
  }
}