Created
October 23, 2018 11:36
-
-
Save dubkov/f00bbd5de2de94606a0cab811fa3663c 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
#include <stdio.h> | |
#include "xtimer.h" | |
#include "timex.h" | |
#include "periph/gpio.h" | |
#define MY_LED_1 GPIO_PIN(PORT_C,8) | |
/* set interval to 1 second */ | |
#define INTERVAL (1U * US_PER_SEC) | |
xtimer_ticks32_t debounce_timer; // <------------------------- | |
void btn_handler(void *arg) | |
{ | |
(void)arg; | |
if ((xtimer_now().ticks32 - debounce_timer.ticks32) > 100000){ // <----- | |
gpio_toggle(MY_LED_1); | |
debounce_timer = xtimer_now(); // <-------------------- | |
} | |
} | |
int main(void) | |
{ | |
debounce_timer = xtimer_now(); // <-------------------- | |
gpio_init(MY_LED_1,GPIO_OUT); | |
gpio_init_int(GPIO_PIN(PORT_A, 0), GPIO_IN, 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