diff --git a/src/main.c b/src/main.c index b97ce6967284eff18858b4232aaf5ff92a5900c7..ccca91dfac74eefb766dcf392254e2c4c0bc6e01 100644 --- a/src/main.c +++ b/src/main.c @@ -4,6 +4,10 @@ #include <unistd.h> #include <hardware/pwm.h> +double percentage_1 = 0; +double percentage_2 = 0; +bool flipflop = false; + const uint8_t init[4] = {0x21, 0xa0, 0xef, 0x81}; const uint8_t zeile[8] = {0x00, 0x02, 0x04, 0x06, 0x08, 0x10, 0x12, 0x14}; const uint8_t fill[17] = {0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; @@ -144,7 +148,18 @@ void callback(uint gpio, uint32_t events) volatile int percentage = (distance / 10) * 100; - set_progress(percentage); + if (flipflop) + { + percentage_1 = percentage; + flipflop = false; + } + else + { + percentage_2 = percentage; + flipflop = true; + } + + set_progress((percentage + percentage_1 + percentage_2) / 3); } else if (events & GPIO_IRQ_EDGE_RISE)