Skip to content

Instantly share code, notes, and snippets.

@cpq
Created August 30, 2020 14:46
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 cpq/ccc4a580dd3a72fb63e854180ff701d9 to your computer and use it in GitHub Desktop.
Save cpq/ccc4a580dd3a72fb63e854180ff701d9 to your computer and use it in GitHub Desktop.
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
if (Serial.available() > 0) {
int character = Serial.read();
if (character == '0') digitalWrite(LED_BUILTIN, LOW); // '0' switches LED off
if (character == '1') digitalWrite(LED_BUILTIN, HIGH); // '1' switches LED on
if (character == '2') Serial.write(digitalRead(LED_BUILTIN) ? "1\n" : "0\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment