-
-
Save juniorxsound/185663ab68323d73e58e74bf47c4b8b3 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
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