From: Roland Hieber Date: Sat, 29 Oct 2011 23:42:57 +0000 (+0200) Subject: tutorial application: binary LED counter via button X-Git-Url: https://git.rohieb.name/wsn-p.git/commitdiff_plain/ac90b067a9353bc7eb577cc48e9dea57c07b220a tutorial application: binary LED counter via button --- diff --git a/tutorial/ledbuttontest/Makefile b/tutorial/ledbuttontest/Makefile new file mode 100644 index 0000000..22c3aad --- /dev/null +++ b/tutorial/ledbuttontest/Makefile @@ -0,0 +1,7 @@ +include ../../Makefile.properties +CONTIKI_PROJECT=ledbuttontest + +all: $(CONTIKI_PROJECT) + +include $(CONTIKI)/Makefile.include + diff --git a/tutorial/ledbuttontest/ledbuttontest.c b/tutorial/ledbuttontest/ledbuttontest.c new file mode 100644 index 0000000..719de36 --- /dev/null +++ b/tutorial/ledbuttontest/ledbuttontest.c @@ -0,0 +1,34 @@ +#include +#include +//#include +#include + +PROCESS(ledbuttontest, "LED button test"); +AUTOSTART_PROCESSES(&ledbuttontest); + +PROCESS_THREAD(ledbuttontest, ev, data) { + PROCESS_BEGIN(); + + leds_init(); + leds_off(LEDS_ALL); + + SENSORS_ACTIVATE(button_sensor); + + static char i; + static struct etimer timer; + for(i = 0; 1; i++) { + PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event && data == &button_sensor); + + // debounce for 250 ms + etimer_set(&timer, CLOCK_SECOND * 0.25); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer)); + + if((i % 2)) { + leds_toggle(LEDS_GREEN); + } + leds_toggle(LEDS_YELLOW); + //printf("toggled\n"); + } + + PROCESS_END(); +}