Created
July 6, 2016 17:16
-
-
Save Mango-kid/a55bac9885dc611567379cc2024f48b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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