#define REED_GPIO 5
#define DEBOUNCE_TIME 100
void handle_reed_switch() {
static bool last_state;
static unsigned long last_millis;
unsigned long current_millis = millis();
if (current_millis - last_millis < DEBOUNCE_TIME) return;
bool current_state = digitalRead(REED_GPIO);
if (current_state == last_state) return;
last_state = current_state;
if (current_state == HIGH) {
Serial.println("Reed-Switch closed");
// send "CLOSE" Event
} else {
Serial.println("Reed-Switch open");
// send "OPEN" Event
}
}
void setup() {
Serial.begin(115200);
pinMode(REED_GPIO, INPUT);
}
void loop() {
handle_reed_switch();
delay(10); // this speeds up the WOKWI-simulation not needed in production!
}