forked from ECE-196/ece-196-fa24-fullstack-FullStack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ino
33 lines (27 loc) · 794 Bytes
/
main.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const int LED { 17 };
// add these
const char S_OK { 0xaa };
const char S_ERR { 0xff };
void setup() {
pinMode(LED, OUTPUT);
// register "on_receive" as callback for RX event
Serial.onEvent(ARDUINO_HW_CDC_RX_EVENT, on_receive);
Serial.begin(9600);
}
void on_receive(void* event_handler_arg, esp_event_base_t event_base, int32_t event_id, void* event_data) {
// read one byte
char state { Serial.read() };
// Serial.print("Received: ");
// Serial.println(state);
// guard byte is valid LED state
if (!(state == LOW || state == HIGH)) {
// invalid byte received
// report error
Serial.write(S_ERR);
return;
}
// update LED with valid state
digitalWrite(LED, state);
Serial.write(S_OK);
}
void loop() {}