Skip to content

Instantly share code, notes, and snippets.

@Mango-kid
Created July 6, 2016 17:16
Show Gist options
  • Save Mango-kid/a55bac9885dc611567379cc2024f48b4 to your computer and use it in GitHub Desktop.
Save Mango-kid/a55bac9885dc611567379cc2024f48b4 to your computer and use it in GitHub Desktop.
/* Read Quadrature Encoder
* Connect Encoder to Pins encoder0PinA, encoder0PinB, and +5V.
*
* Sketch by max wolf / www.meso.net
* v. 0.1 - very basic functions - mw 20061220
*
*/
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment