Hello, 

My code is below. I am trying to program my Tmote Invents to detect a sound 
at a certain level and then change LEDs. The way it should work is the red led 
is set upon start up. I have also set up a timer to fire every 5 seconds 
5*1024. What should happen is that when I clap, the green Led is turned on and 
the red Led is turned off. Once the 5 second interval has completed, I then 
want the green light to cut off again and return to red. Can anyone see what 
I'm doing wrong. The code compiles and the red light is set, but I am unable to 
trigger the green light. 

module MicDetectM
{
  provides interface StdControl;
  uses {
    interface Timer;
    interface Leds;
 interface SensorInterrupt as MicInterrupt;
 
 interface Potentiometer as MicInterruptThreshold; 
 interface Potentiometer as Vrc;
 interface Potentiometer as Vrg;
 
 //interface Microphone;  to be incorporated
  }
}
implementation
{
 /*Declare Constants and variables */
    /* Put Constant Here , */
  enum {TIMER_INTERVAL = 5*1024};  /* Timer repeat every 5 seconds */
  enum {MIC_INT_THRESH = -40};
/* Declare Tasks Here */

/***** Start Control Here ***/
/****   TIMER *****/
  event result_t Timer.fired() {
    /*  reset memory if a interupt has not occured */
 call Leds.greenOff();
 call Leds.redOn();
 return SUCCESS;
 }
/********** Start Application *********/
  command result_t StdControl.init() {
    call Leds.init();
 call  MicInterruptThreshold.set(MIC_INT_THRESH); 
 call Vrc.set(1);
 call Vrg.set(0);
    return SUCCESS;
 }
 
  command result_t StdControl.start() {
    return call Timer.start( TIMER_REPEAT, TIMER_INTERVAL );
 return call MicInterrupt.enable();
    //return SUCCESS; 
    }
/**** Turn Stuff Off **/
/******* code to be executed upon finishing the recording *******/
  //async event void Microphone.done( void *addr, uint16_t length ) {
    //post recordingFinishedTask();
  //}
  event void Vrg.setDone( uint8_t value, result_t result){}
  event void Vrc.setDone( uint8_t value, result_t result){}
  event void MicInterruptThreshold.setDone(uint8_t _gain, result_t _result) { }
  async event void MicInterrupt.fired() {
    atomic { call Leds.greenOn();
    call Leds.redOff(); }
 }
/*********************End Application ********/
  command result_t StdControl.stop() {
 return call MicInterrupt.disable();
    //return SUCCESS;
 }
}
---------------------------------------------------------------------- Respectfully,
 


Jacob H. Cox Jr
(706) 413-3841
"What ever you do, work at it with all your heart, as working for the Lord..." 
Colossians 3:23 
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to