Created
October 28, 2012 09:18
-
-
Save tmpvar/3968145 to your computer and use it in GitHub Desktop.
This file contains 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
void setup() { | |
pinMode(13, OUTPUT); | |
Serial.begin(9600); | |
} | |
int lasta=0, lastb=0; | |
int dira=0, dirb=0; | |
int peaka=346, peakb=349; | |
int position = 0; | |
int cycle = 0; | |
void loop() { | |
digitalWrite(13, HIGH); | |
int currenta = analogRead(0); | |
int currentb = analogRead(1); | |
if (currenta == lasta || currentb == lastb) { | |
return; | |
} | |
//Serial.print(currenta); | |
//Serial.print(" - "); | |
//Serial.println(currentb); | |
if (currenta > currentb) { | |
if (currenta == peaka) { | |
// CW | |
if (currentb > lastb) { | |
position++; | |
// CCW | |
} else if (currentb < lastb) { | |
position--; | |
} | |
} | |
} else if (currentb > currenta) { | |
if (currentb == peakb) { | |
// CW | |
if (currenta < lasta) { | |
position++; | |
// CCW | |
} else if (currenta > lasta) { | |
position--; | |
} | |
} | |
} | |
Serial.println(position); | |
lasta = currenta; | |
lastb = currentb; | |
delay(20); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment