Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@juniorxsound
Created December 14, 2016 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juniorxsound/185663ab68323d73e58e74bf47c4b8b3 to your computer and use it in GitHub Desktop.
Save juniorxsound/185663ab68323d73e58e74bf47c4b8b3 to your computer and use it in GitHub Desktop.
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