summaryrefslogtreecommitdiff
path: root/api_layers/arduino_layer.py
diff options
context:
space:
mode:
authorChristian Kolset <christian.kolset@gmail.com>2026-04-21 22:58:30 -0600
committerChristian Kolset <christian.kolset@gmail.com>2026-04-21 22:58:30 -0600
commit4db119fb9c04428e7aef6f1a278c1639aa867baf (patch)
treee0e0645559637e593f1bbfb9d713256028668527 /api_layers/arduino_layer.py
parent97e15f69b835af03b071c4eeb4547c65a02e6f80 (diff)
Major update to Output control
Including: - Control panel - Change status of simulation after devices creation. - Arduino serial conflict with multiple channels. - Claude instructions. - Update to arduino on board code.
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
}
"""