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&OpenJumper.For surport
materials and a full range of system boards &
periphrals please visit : http://www.arduino.cn http://www.openjumper.com
created & modified 15 Dec 2012
by i3water
*/
void read_quadrature(){
// found a low-to-high on channel A ENA腳下降沿中斷觸發(fā)
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腳上升沿中斷觸發(fā)
else{
// check channel B to see which way 查詢ENB的電平以確認是順時針還是逆時針旋轉
if (digitalRead(ENCODER_B_PIN) == LOW)
position--;
}
}