Skip to content

Instantly share code, notes, and snippets.

@REPTILEHAUS
Created February 25, 2017 14:49
Show Gist options
  • Save REPTILEHAUS/b4b36ee89668324779fe001bc0554673 to your computer and use it in GitHub Desktop.
Save REPTILEHAUS/b4b36ee89668324779fe001bc0554673 to your computer and use it in GitHub Desktop.
// Assign each of our input pins to an integer variable
int LED_one = 13;
void setup() {
Serial.begin( 9600 );
pinMode( LED_one, OUTPUT );
}
void loop() {
while (Serial.available() == 0); //wait until the serial connection is open
int COM_value = Serial.read() - '0'; //read from the serial connection; the - '0' is to cast the values as the int and not the ASCII code
Serial.println(COM_value); //print to the console for testing
if( COM_value == 1 ) { //LED #`1
Serial.println("Received a 1 - ON");
digitalWrite( LED_one, HIGH ); // HIGH VOLTAGE - TURNED ON
}
if( COM_value == 2 ) {
Serial.println("Received a 2 - OFF");
digitalWrite( LED_one, LOW ); // LOW VOLTAGE - TURNED OFF
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment