Created
November 6, 2018 05:25
-
-
Save eroeber/ddb7b4577aa4dd6341a5c179ec63ffd1 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 pot = 0; // potentiometer | |
int push = 0; // presser sensor | |
int incoming; // stores incoming data (clicks sent from p5) | |
void setup() { | |
Serial.begin(9600); | |
pinMode(7, OUTPUT); // green LED | |
pinMode(4, OUTPUT); // blue LED | |
pinMode(2, OUTPUT); // yellow LED | |
} | |
void loop() { | |
int potVal = analogRead(A0); // potentiometer pin | |
int pushVal = analogRead(A1); // pressure sensor pin | |
// min of pot = 0 , max of pot = 1023 | |
// min of push = 0 , max of push = 990 about | |
// initial testing of sensors | |
// Serial.println(pushVal); | |
// Serial.print("Potentiometer: "); | |
// Serial.print(potVal); | |
// Serial.print(" || Pressure: "); | |
// Serial.println(pushVal); | |
// BINARY: | |
// send a single byte (range 0 - 255) | |
// ASCII: larger messages | |
// format it correctly so p5 can parse it correctly | |
Serial.print(potVal); | |
Serial.print(","); | |
Serial.println(pushVal); | |
// sending messages from p5 to arduino | |
if(Serial.available() > 0){ | |
incoming = Serial.read(); // store data onto incoming variable | |
// light up green LED if top region is clicked | |
if(incoming > 0 && incoming < 80){ | |
digitalWrite(7, HIGH); | |
digitalWrite(4, LOW); | |
digitalWrite(2, LOW); | |
} | |
// light up blue LED if middle region is clicked | |
if(incoming > 80 && incoming < 160){ | |
digitalWrite(7, LOW); | |
digitalWrite(4, HIGH); | |
digitalWrite(2, LOW); | |
} | |
// light up yellow LED if bottom region is clicked | |
if(incoming > 160 && incoming < 350){ | |
digitalWrite(7, LOW); | |
digitalWrite(4, LOW); | |
digitalWrite(2, HIGH); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment