From b0d91e6290ccd2292091a064283a9287821abb36 Mon Sep 17 00:00:00 2001 From: Gregor Riepl Date: Mon, 8 Feb 2021 16:50:57 +0100 Subject: [PATCH] Antiglitch, try 3 --- feedback/firmware/main.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/feedback/firmware/main.c b/feedback/firmware/main.c index 8eca023..0937eb0 100644 --- a/feedback/firmware/main.c +++ b/feedback/firmware/main.c @@ -62,8 +62,11 @@ static uint16_t get_status() { static uint16_t graded_status() { uint16_t status = get_status(); - // combine the bits of the last 3 states into one: "3 successive ones" - uint16_t graded = status_hysteresis[0] & status_hysteresis[1] & status; + // report a one bit if the majority of the last states had a one + uint16_t graded = + (status_hysteresis[0] & status_hysteresis[1]) | + (status_hysteresis[1] & status) | + (status_hysteresis[0] & status); status_hysteresis[0] = status_hysteresis[1]; status_hysteresis[1] = status; @@ -113,7 +116,7 @@ static void loop() { } } - _delay_us(100); + _delay_ms(200); } int main() {