Read a rotary encoder with interrupts Read the press action with digitalread Encoder&Switch hooked up with common to +5V ENCODER_A_PIN to pin 2 ENCODER_A_PIN to pin 3 SWITCH_PIN to pin 4
Published by ArduinoCN&XXXXXXXXXXXXXr surport materials and a full range of system boards & periphrals please visit : XXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXXXXXXXXXX created & modified 15 Dec 2012 by i3water */
void read_quadrature(){ // found a low-to-high on channel A ENA脚下降沿中断触发 if (digitalRead(ENCODER_A_PIN) == LOW){ // check channel B to see which way 查询ENB的电平以确认是顺时针还是逆时针旋转 if (digitalRead(ENCODER_B_PIN) == LOW) position++; } // found a high-to-low on channel A ENA脚上升沿中断触发 else{ // check channel B to see which way 查询ENB的电平以确认是顺时针还是逆时针旋转 if (digitalRead(ENCODER_B_PIN) == LOW) position--; } }