BGGLand
rotary encoder - Version imprimable

+- BGGLand (http://bgg.kicks-ass.org)
+-- Forum : La parole est à vous (http://bgg.kicks-ass.org/forumdisplay.php?fid=7)
+--- Forum : Les blablas de tout et de rien. (http://bgg.kicks-ass.org/forumdisplay.php?fid=8)
+--- Sujet : rotary encoder (/showthread.php?tid=104)



rotary encoder - BGG - 30-09-2016

int val; 
int encoder0PinA = 3; 
int encoder0PinB = 4; 
int encoder0Pos = 0; 
int encoder0PinALast = LOW; 
int n = LOW; 

void setup()
{   
pinMode (encoder0PinA,INPUT);
pinMode (encoder0PinB,INPUT);   
Serial.begin (9600); 


void loop()
{   
n = digitalRead(encoder0PinA);   
if ((encoder0PinALast == LOW) && (n == HIGH))
{     
if (digitalRead(encoder0PinB) == LOW)
{       
encoder0Pos--;
}
else
{       
encoder0Pos++;     
}     
Serial.print (encoder0Pos);
Serial.print ("/");   
}   
encoder0PinALast = n; 
}