From ac90b067a9353bc7eb577cc48e9dea57c07b220a Mon Sep 17 00:00:00 2001 From: Roland Hieber Date: Sun, 30 Oct 2011 01:42:57 +0200 Subject: [PATCH] tutorial application: binary LED counter via button --- tutorial/ledbuttontest/Makefile | 7 ++++++ tutorial/ledbuttontest/ledbuttontest.c | 34 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 tutorial/ledbuttontest/Makefile create mode 100644 tutorial/ledbuttontest/ledbuttontest.c 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(); +} -- 2.20.1