Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
int pot1;
int pot2;
int currentPot1, lastPot1;
int currentPot2, lastPot2;
void setup() {
Serial.begin(9600);
}
void loop() {
readPots();
sendSerial();
matchStates();
delay(100);
}
void readPots(){
pot1 = analogRead(A0);
pot2 = analogRead(A1);
currentPot1 = map(pot1, 0, 1023, 199, 152);
currentPot2 = map(pot2, 0, 1023, 255, 200);
}
void sendSerial(){
if(currentPot1 != lastPot1){
Serial.write(currentPot1);
}
if(currentPot2 != lastPot2){
Serial.write(currentPot2);
}
}
void matchStates(){
lastPot1 = currentPot1;
lastPot2 = currentPot2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment