// https://wokwi.com/projects/394966869925182465
// for https://forum.arduino.cc/t/resetting-data-for-addressable-leds/1245705/54
const int OnPin = 2;
const int AutoPin = 3;
const int Active = LOW;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Simulate on-off-on SPDT switch with Wokwi components");
pinMode(OnPin, INPUT_PULLUP);
pinMode(AutoPin, INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
static int lastPins = -1; // initial value to trigger a change/report on powerup
const int debounceBlanking = 5; // rate limiting blanking of future changes
static uint32_t lastChange = -debounceBlanking; // rollover negative to allow change on powerup
int newPins = (digitalRead(OnPin) == Active) << 1 | digitalRead(AutoPin) == Active;
if (newPins != lastPins && millis() - lastChange > debounceBlanking ) {
lastPins = newPins;
lastChange = millis();
switch (newPins) {
case 0: Serial.print("Off"); break;
case 1: Serial.print("Auto"); break;
case 2: Serial.print("On"); break;
case 3: Serial.print("Both (shouldn't happen)"); break;
default: Serial.print("Other"); break;
}
Serial.print(" ");
}
}
On-Off-On from two On-On SPDT
Enable
1 or 2