summaryrefslogtreecommitdiff
path: root/api_layers/arduino_layer.py
diff options
context:
space:
mode:
Diffstat (limited to 'api_layers/arduino_layer.py')
-rw-r--r--api_layers/arduino_layer.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/api_layers/arduino_layer.py b/api_layers/arduino_layer.py
index fb09a16..fed54f9 100644
--- a/api_layers/arduino_layer.py
+++ b/api_layers/arduino_layer.py
@@ -551,7 +551,7 @@ const int DIGITAL_IN[] = {2, 3, 4};
const int DIGITAL_OUT[] = {5, 6, 7, 9, 10, 11}; // 9,10,11 are PWM-capable
const int N_ANALOG = 1; // ← set to how many analog pins you use
const int N_DIG_IN = 0; // ← set to how many digital inputs you use
-const int N_DIG_OUT = 0; // ← set to how many digital outputs you use
+const int N_DIG_OUT = 6; // ← set to how many digital outputs you use
const int SEND_INTERVAL = 50; // ms between data frames (50 = 20 Hz)
const long BAUD_RATE = 115200;
@@ -666,16 +666,22 @@ void sendData() {
void sendFrame() {
String out = "";
+ bool first = true;
// Analog inputs — converted to 0.0–5.0 V
for (int i = 0; i < N_ANALOG; i++) {
float v = analogRead(ANALOG_PINS[i]) * (5.0 / 1023.0);
- if (i > 0) out += ",";
+ if (!first) out += ",";
out += "A" + String(i) + ":" + String(v, 3);
+ first = false;
}
// Digital inputs (INPUT_PULLUP — invert so pressed=1)
+ // These share the same output line as analog — one line per frame.
for (int i = 0; i < N_DIG_IN; i++) {
- out += ",D" + String(DIGITAL_IN[i]) + ":" + String(!digitalRead(DIGITAL_IN[i]));
+ if (!first) out += ",";
+ out += "D" + String(DIGITAL_IN[i]) + ":" + String(!digitalRead(DIGITAL_IN[i]));
+ first = false;
}
Serial.println(out);
+ // Example combined output: A0:3.142,D2:0,D3:1
}
"""