やりたいこと
現在Arduino Leonardoを使ってロータリーエンコーダーが
停止しているのか、左に回転しているのか、右に回転しているのかを取得したい。
現在Arduino Leonardoを使って
ロータリーエンコーダーの状態を取得しようとしています。
こちらのライブラリを使用して書き込みをしてみたのですが
エラーが発生してしまって困っています。
やっていること
スケッチ例→Rotary-Master→Interrupt
をArduino leonaldoに書き込んだ
/* Rotary Encoder - Interrupt Example The circuit: * encoder pin A to Arduino pin 2 * encoder pin B to Arduino pin 3 * encoder ground pin to ground (GND) */ #include <Rotary.h> Rotary r = Rotary(2, 3); void setup() { Serial.begin(9600); r.begin(); PCICR |= (1 << PCIE2); PCMSK2 |= (1 << PCINT18) | (1 << PCINT19); sei(); } void loop() { } ISR(PCINT2_vect) { unsigned char result = r.process(); if (result == DIR_NONE) { // do nothing } else if (result == DIR_CW) { Serial.println("ClockWise"); } else if (result == DIR_CCW) { Serial.println("CounterClockWise"); } }
エラーの内容
書き込みをする際に
'PCIE2' was not declared in this scope 'PCINT19' was not declared in this scope
これらのエラーが発生します。
エラー解決のためにやったこと
PCIE2,PCINTが定義されていないという内容なので
こちらのサイトを参考に
PCICR |= (1 << PCIE2); PCMSK2 |= (1 << PCINT18) | (1 << PCINT19);
の部分を
PCICR |= B00000100; PCMSK2 |= B00001000|B00000100;
と書き換えてみましたが
'PCMSK2' was not declared in this scope
と表示され、いまいち解決できそうにありません。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/07/22 01:35
2022/12/22 02:14