Created
March 3, 2016 20:28
-
-
Save augustoguerrero/79637cc48b57c4986880 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include "contiki.h" | |
#include "dev/i2cmaster.h" | |
#include "dev/light-ziglet.h" | |
#include "dev/leds.h" | |
/*---------------------------------------------------------------------------*/ | |
#define SENSOR_READ_INTERVAL (CLOCK_SECOND / 80) | |
#define SENSOR_SAMPLE_INTERVAL (CLOCK_SECOND / 40) | |
//uint32_t medir_luz(uint32_t muestras); | |
/*---------------------------------------------------------------------------*/ | |
PROCESS(test_process, "Test light ziglet process"); | |
AUTOSTART_PROCESSES(&test_process); | |
/*---------------------------------------------------------------------------*/ | |
static struct etimer et; | |
uint32_t sample, medicion; | |
uint32_t suma = 0; | |
/*---------------------------------------------------------------------------*/ | |
#define SAMPLES 1 | |
uint32_t base; | |
PROCESS_THREAD(test_process, ev, data){ | |
PROCESS_BEGIN(); | |
/* Initialize driver and set a slower data rate */ | |
light_ziglet_init(); | |
i2c_setrate(I2C_PRESC_100KHZ_LSB, I2C_PRESC_100KHZ_MSB); | |
suma = 0; | |
for(sample=0; sample < SAMPLES; sample++){ | |
etimer_set(&et, SENSOR_SAMPLE_INTERVAL); | |
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); | |
suma = suma + light_ziglet_read(); | |
} | |
base = suma / SAMPLES; | |
while(1) { | |
etimer_set(&et, SENSOR_READ_INTERVAL); | |
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); | |
/* suma = 0; | |
for(sample=0; sample < SAMPLES; sample++){ | |
etimer_set(&et, SENSOR_SAMPLE_INTERVAL); | |
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); | |
suma = suma + light_ziglet_read(); | |
} */ | |
//medicion = suma / SAMPLES; | |
medicion = light_ziglet_read(); | |
printf("Medicion %u\n", medicion); | |
if(medicion < base/2){ | |
leds_toggle(LEDS_BLUE); | |
//printf("Light = %u-%u\n", light_ziglet_read(),prom*.1); | |
} | |
} | |
PROCESS_END(); | |
} | |
/*---------------------------------------------------------------------------*/ | |
/* | |
uint32_t medir_luz(uint32_t muestras) { | |
uint32_t i; | |
uint32_t suma = 0; | |
for(i=0; i < muestras; i++){ | |
etimer_set(&et, SENSOR_SAMPLE_INTERVAL); | |
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); | |
suma = suma + light_ziglet_read(); | |
} | |
return suma / muestras; | |
}*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment