Hi all,

Here is my code to measure light with TelosB. The program should write the 
light value to serial port. It does but it only outpus 4037... I know that I 
have to convert this number, but the thing is the sensor is not working at all, 
I mean if I cover the light sensor and make it dark, my program still outputs 
4037 to terminal. Can you please check my program?

-----------------------------------
 *LightSensorAppC.nc*
-----------------------------------

configuration LightSensorAppC
{
}

implementation
{
 components LightSensorC as App;
 components MainC, LedsC;
 components new TimerMilliC();
 components new DemoSensorC() as LightSensor;

 components new HamamatsuS10871TsrC() as Light;

 //UART1
 //Necessery for "printf" command to work
 components SerialPrintfC;

 App.Boot -> MainC;
 App.Leds -> LedsC;
 App.Timer -> TimerMilliC;
 App.Read -> LightSensor;
}

----------------------------------
 *LightSensorC.nc*
----------------------------------
#include <Timer.h>
#include <stdio.h>
#include <string.h>


module LightSensorC
{
 uses
 {
 interface Boot;
 interface Timer<TMilli>;
 interface Read<uint16_t>;
 interface Leds;
 }
}

implementation
{
 /*********** Variables **********/


 /********** Custom Functions ***********/

 //Turn led1 ON when board is ON
 void sensorBoardOn(){ call Leds.led1On(); }

 //Turn led0 ON in case of problem
 void reportProblem(){ call Leds.led0Toggle(); }

 //Turn led2 ON if light is being detected
 void lightIsDetected(){ call Leds.led2On(); }

 //Turn led2 OFF is light is not detected
 void lightNotDetected(){ call Leds.led2Off(); }

 //Starts the timer and fills variables
 void startTimer()
 {
 call Timer.startPeriodic(1000); 
 }

 /******************** EVENTS *******************/

 //uC boot event 
 event void Boot.booted()
 {
 sensorBoardOn();
 startTimer(); 
 }

 //Timer event
 event void Timer.fired()
 {
 if(call Read.read() == SUCCESS)
 {
 lightIsDetected();
 } 
 }

 //Read event
 event void Read.readDone(error_t result, uint16_t val)
 {
 // TODO Auto-generated method stub
 if(result == SUCCESS)
 {
 call Leds.led2Toggle();
 printf("%d\r\n", val);
 }
 else
 {
 reportProblem();
 }
 }
}

---------------
 *Makefile*
---------------
COMPONENT = LightSensorAppC
PFLAGS += -I$(TOSDIR)/lib/printf
include $(MAKERULES)
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to