Skip to content

Instantly share code, notes, and snippets.

@benmanns
Last active December 13, 2015 19:38
Show Gist options
  • Save benmanns/4964277 to your computer and use it in GitHub Desktop.
Save benmanns/4964277 to your computer and use it in GitHub Desktop.
Controlling the LED by sending Y or N over the serial connection.
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
Serial.println("Y for on, N for off.");
}
int ledOn = 0;
void loop() {
int instruction = 0;
while (Serial.available() > 0) {
instruction = Serial.read();
if (instruction == 89 && ledOn == 0) {
ledOn = 1;
digitalWrite(13, HIGH);
}
else if (instruction == 78 && ledOn == 1) {
ledOn = 0;
digitalWrite(13, LOW);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment