Skip to content

Instantly share code, notes, and snippets.

@telent
Created July 20, 2018 10:43
Show Gist options
  • Save telent/cefe505dff0f8399476850dac200ca0a to your computer and use it in GitHub Desktop.
Save telent/cefe505dff0f8399476850dac200ca0a to your computer and use it in GitHub Desktop.
#define RELAY_PIN (8)
void setup() {
// put your setup code here, to run once:
SERIAL_PORT_USBVIRTUAL.begin(115200); // open serial connection via USB-Serial
pinMode(RELAY_PIN, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int c = SERIAL_PORT_USBVIRTUAL.read(); // read from USB-CDC
switch(c) {
case '1': case 'y':
digitalWrite(RELAY_PIN, HIGH);
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
break;
case '0': case 'n':
digitalWrite(RELAY_PIN, LOW);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
break;
default:
delay(10);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment