Created
August 22, 2018 12:24
-
-
Save dubkov/52e89bd6885ec38c7ac1c2a61a09c2f8 to your computer and use it in GitHub Desktop.
riot-debounce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// BUTTON WITHOUT THREAD | |
#include <stdio.h> | |
#include "periph/gpio.h" | |
#include "xtimer.h" | |
#include "timex.h" | |
#include <string.h> | |
#include "thread.h" | |
xtimer_ticks32_t timerPrev; | |
static void btn_handler(void *arg){ | |
(void)arg; | |
if (xtimer_now().ticks32 - timerPrev.ticks32 > 50){ | |
timerPrev = xtimer_now(); | |
gpio_toggle(GPIO_PIN(PORT_B, 0)); | |
puts("Button press!"); | |
} | |
} | |
int main(void) | |
{ | |
gpio_init(GPIO_PIN(PORT_B, 0), GPIO_OUT); | |
gpio_init_int(GPIO_PIN(PORT_B, 1), GPIO_IN_PU, GPIO_FALLING, btn_handler, NULL); | |
// while(1); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment