/* - Raspberry Pi Pico W + two DS18B20 sensors + status LED • Built-in error check on readTemp() → GUI only sees valid data • When overrideActive==true → tempThreshold logic is bypassed • Outputs every 1 s: mean;t1;t2\n • Accepts single-byte commands: '1'→LED ON, '0'→LED OFF */ #include // DS18B20 MicroMicro library // Pins Definition MicroDS18B20<26> sensor1; // DS18B20 on GPIO 26 MicroDS18B20<27> sensor2; // DS18B20 on GPIO 27 #define LED_PIN 22 // status LED // Temperature Threshold const float tempThreshold = 23.0; // auto-LED ON above this mean °C // Set-up void setup() { Serial.begin(9600); // baudrate should match the Processing sketch pinMode(LED_PIN, OUTPUT); } // Global variables bool overrideActive = false; //initially OFF bool overrideState = false; void loop() { // Process any incoming 1s/0s commands immediately while (Serial.available()) { char c = Serial.read(); if (c == '1') { overrideActive = true; overrideState = true; } else if (c == '0') { overrideActive = true; overrideState = false; } // ignore anything else } // Kick off conversions sensor1.requestTemp(); sensor2.requestTemp(); delay(1000); // wait for the DS18B20 sensor // Read temperature values and compute mean bool ok1 = sensor1.readTemp(); bool ok2 = sensor2.readTemp(); if (ok1 && ok2) { float t1 = sensor1.getTemp(); float t2 = sensor2.getTemp(); float meanT = 0.5 * (t1 + t2); // apply LED logic with override if (overrideActive) { digitalWrite(LED_PIN, overrideState ? HIGH : LOW); } else { digitalWrite(LED_PIN, meanT >= tempThreshold ? HIGH : LOW); } // send CSV line Serial.print(meanT, 2); Serial.print(';'); Serial.print(t1, 2); Serial.print(';'); Serial.println(t2, 2); } // loop back and wait for next command! }