Skip to content

Instantly share code, notes, and snippets.

@dubkov
Created August 22, 2018 12:24
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/52e89bd6885ec38c7ac1c2a61a09c2f8 to your computer and use it in GitHub Desktop.
Save dubkov/52e89bd6885ec38c7ac1c2a61a09c2f8 to your computer and use it in GitHub Desktop.
riot-debounce
// 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