arduino-sketch.ino 425 B

12345678910111213141516
  1. const uint8_t PIN = 4;
  2. void setup() {
  3. // $ stty -F /dev/ttyUSB0 | grep speed
  4. Serial.begin(115200);
  5. pinMode(PIN, OUTPUT);
  6. }
  7. void loop() {
  8. // https://www.arduino.cc/reference/en/language/functions/communication/serial/read/
  9. if (Serial.available() > 0) {
  10. // $ printf '\0' > /dev/ttyUSB0
  11. // $ printf '\x01' > /dev/ttyUSB0
  12. digitalWrite(PIN, (Serial.read() > 0) ? HIGH : LOW);
  13. }
  14. }