tutorial application: binary LED counter via button
authorRoland Hieber <rohieb@rohieb.name>
Sat, 29 Oct 2011 23:42:57 +0000 (01:42 +0200)
committerRoland Hieber <rohieb@rohieb.name>
Sat, 29 Oct 2011 23:42:57 +0000 (01:42 +0200)
tutorial/ledbuttontest/Makefile [new file with mode: 0644]
tutorial/ledbuttontest/ledbuttontest.c [new file with mode: 0644]

diff --git a/tutorial/ledbuttontest/Makefile b/tutorial/ledbuttontest/Makefile
new file mode 100644 (file)
index 0000000..22c3aad
--- /dev/null
@@ -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 (file)
index 0000000..719de36
--- /dev/null
@@ -0,0 +1,34 @@
+#include <contiki.h>
+#include <leds.h>
+//#include <stdio.h>
+#include <dev/button-sensor.h>
+
+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();
+}
This page took 0.024683 seconds and 4 git commands to generate.