Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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