Skip to content

Instantly share code, notes, and snippets.

@dubkov
Created October 23, 2018 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dubkov/f00bbd5de2de94606a0cab811fa3663c to your computer and use it in GitHub Desktop.
Save dubkov/f00bbd5de2de94606a0cab811fa3663c to your computer and use it in GitHub Desktop.
RIOT DEBOUNCE
#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