Browse Source

arduino: set pin 4 to high/low based on byte received through serial interface

Fabian Peter Hammerle 3 years ago
commit
d435d79800
4 changed files with 20 additions and 0 deletions
  1. 1 0
      .gitattributes
  2. 1 0
      .gitignore
  3. 2 0
      Makefile
  4. 16 0
      arduino-sketch.ino

+ 1 - 0
.gitattributes

@@ -0,0 +1 @@
+*.jpg filter=lfs diff=lfs merge=lfs -text

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+/build-*/

+ 2 - 0
Makefile

@@ -0,0 +1,2 @@
+BOARD_TAG = uno
+include /usr/share/arduino/Arduino.mk

+ 16 - 0
arduino-sketch.ino

@@ -0,0 +1,16 @@
+const uint8_t PIN = 4;
+
+void setup() {
+    // $ stty -F /dev/ttyUSB0 | grep speed
+    Serial.begin(115200);
+    pinMode(PIN, OUTPUT);
+}
+
+void loop() {
+    // https://www.arduino.cc/reference/en/language/functions/communication/serial/read/
+    if (Serial.available() > 0) {
+        // $ printf '\0' > /dev/ttyUSB0
+        // $ printf '\x01' > /dev/ttyUSB0
+        digitalWrite(PIN, (Serial.read() > 0) ? HIGH : LOW);
+    }
+}