LoginSignup
2
0

More than 1 year has passed since last update.

Arduinoのタイマー割り込みで遊ぶ

Last updated at Posted at 2022-04-28

目的
オリジナルI2C超音波距離センサーからの値を定期的に受信したい。
とりあえず500msで割り込みをかけた。

o_con360.jpg

参考

ArduinoのTimerを初心者が1からなんとなくわかるためのメモ




// 1/100秒の指定
#define AA 50
#define BB (65536-((62500/100)*AA))

void setup() {
  Serial.begin(9600);
  
  TCCR1A = 0; // 初期化
  TCCR1B = 0; // 初期化
  //TCNT1 = 3036; 
  TCNT1 = BB;
  TCCR1B |= (1 << CS12);  //CS12 -> 1  prescaler = 256
  TIMSK1 |= (1 << TOIE1); //TOIE -> 1
}

ISR(TIMER1_OVF_vect) {
  Serial.println(millis());
  //TCNT1 = 3036;
  TCNT1 = BB;
}

void loop() {
}




2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0