From af12d888e89cb352bb99c3d001ff4137e9e3d8c1 Mon Sep 17 00:00:00 2001 From: "jamesimmanuel.magsino@stud.h-da.de" <James Immanuel Magsino> Date: Tue, 3 Dec 2024 13:00:49 +0100 Subject: [PATCH] edge trigger stuff --- src/main.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main.c b/src/main.c index 16a6d1c..658461d 100644 --- a/src/main.c +++ b/src/main.c @@ -122,19 +122,29 @@ void callback(uint gpio, uint32_t events) { volatile uint slice_num = pwm_gpio_to_slice_num(27); - volatile duration = pwm_get_counter(slice_num) * 42; - /* volatile uint another_slice_num = pwm_gpio_to_slice_num(27); - if (events & GPIO_IRQ_LEVEL_HIGH) + if (events & GPIO_IRQ_EDGE_FALL) { - volatile uint16_t test = pwm_get_counter(another_slice_num); + volatile uint16_t duration = pwm_get_counter(slice_num) * 42; + volatile uint16_t test = pwm_get_counter(slice_num); + volatile float distance = (test * 314) / (20000); + if (distance > 20) + { + distance = 20; + } + + distance = 20 - distance; + + volatile int percentage = (distance / 10) * 100; + + set_progress(percentage); } - else if (events & GPIO_IRQ_LEVEL_LOW) + else if (events & GPIO_IRQ_EDGE_RISE) { - pwm_set_counter(another_slice_num, 0); + pwm_set_counter(slice_num, 0); } - */ + // volatile uint16_t test = pwm_get_counter(another_slice_num); // volatile float distance = (test * 314) / (20000); // if (distance > 20) -- GitLab