Contiki 2.5
battery-monitor.c
1 #include "contiki.h"
2 #include "dev/battery-sensor.h"
3 #include "lib/sensors.h"
4 #include <stdio.h> /* For printf() */
5 /*---------------------------------------------------------------------------*/
6 PROCESS(battery_monitor_process, "Battery Voltage Monitor");
7 AUTOSTART_PROCESSES(&battery_monitor_process);
8 /*---------------------------------------------------------------------------*/
9 PROCESS_THREAD(battery_monitor_process, ev, data)
10 {
11  static struct etimer et;
12 
13  PROCESS_BEGIN();
14 
15  SENSORS_ACTIVATE(battery_sensor);
16 
17  while(1) {
18 
19  etimer_set(&et, CLOCK_SECOND * 2);
21  /*
22  * Battery voltage calculation formula
23  *
24  * V(Battery Voltage) = v(Voltage Reference) * 1024 / ADC
25  *
26  * Where:
27  * v = 1.223
28  *
29  */
30  printf("ADC value : %d\n", battery_sensor.value(0));
31  }
32  PROCESS_END();
33 }
34 /*---------------------------------------------------------------------------*/