Skip to content

Instantly share code, notes, and snippets.

@rehrumesh
Created April 24, 2015 03:46
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 rehrumesh/10cfc768116331cbfcea to your computer and use it in GitHub Desktop.
Save rehrumesh/10cfc768116331cbfcea to your computer and use it in GitHub Desktop.
#include "contiki.h"
#include "dev/button-sensor.h"
#include "dev/leds.h"
#include <stdio.h>
PROCESS(blink_process, "Blink");
AUTOSTART_PROCESSES(&blink_process);
PROCESS_THREAD(blink_process,ev,data){
PROCESS_BEGIN();
SENSORS_ACTIVATE(button_sensor);
static int value = 0;
while(1){
PROCESS_WAIT_EVENT();
static struct etimer et;
if(ev == sensors_event && data == &button_sensor){
printf("Button press event :\n");
value = value +1;
if(value == 1){
etimer_set(&et, CLOCK_SECOND);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
leds_on(LEDS_RED);
}else if(value == 2){
etimer_set(&et, CLOCK_SECOND);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
leds_on(LEDS_GREEN);
}else if(value == 3){
etimer_set(&et, CLOCK_SECOND);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
leds_on(LEDS_BLUE);
}else{
etimer_set(&et, CLOCK_SECOND);
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
leds_off(LEDS_ALL);
value = 0 ;
}
}
}
PROCESS_END();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment