diff --git a/tasks/task1_1/main.c b/tasks/task1_1/main.c index fb0890133f89baac96c73a254d8331e2a31c2992..fbd141f8a389ee2ac851fef8c4fc72e7de94c485 100644 --- a/tasks/task1_1/main.c +++ b/tasks/task1_1/main.c @@ -1,22 +1,28 @@ #include <stdio.h> +#include <stdint.h> #include "board.h" #include "periph/gpio.h" #include "ztimer.h" int main(void) { -// gpio_t led = LED0_PIN;// GPIO_PIN(0, 2); gpio_init(LED0_PIN, GPIO_OUT); gpio_init(BTN0_PIN, GPIO_IN_PU); + uint8_t prev_state = 0; + uint8_t curr_state = 0; + for (;;) { - if (!gpio_read(BTN0_PIN)) { - gpio_set(LED0_PIN); - } else { - gpio_clear(LED0_PIN); + prev_state = curr_state; + curr_state = !gpio_read(BTN0_PIN); + + if (curr_state > prev_state) { + gpio_toggle(LED0_PIN); + ztimer_sleep(ZTIMER_USEC, 200 * US_PER_MS); } - ztimer_sleep(ZTIMER_USEC, 10 * US_PER_MS); + ztimer_sleep(ZTIMER_USEC, 100 * US_PER_MS); } + return 0; }