22 lines
423 B
Arduino
22 lines
423 B
Arduino
|
const byte PIN_ROT = 2;
|
||
|
volatile unsigned long counter = 0;
|
||
|
|
||
|
void count(){
|
||
|
static byte rot[2] = {0}; //rot[0]:今の状態, rot[1]:前回の状態
|
||
|
rot[0] = digitalRead(PIN_ROT);
|
||
|
if(rot[0] != rot[1]){
|
||
|
rot[1] = rot[0];
|
||
|
counter++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void setup(){
|
||
|
Serial.begin(9600);
|
||
|
pinMode(PIN_ROT, INPUT);
|
||
|
}
|
||
|
|
||
|
void loop(){
|
||
|
count(); //ロータリーエンコーダーの変化を見る
|
||
|
Serial.println(counter);
|
||
|
}
|