//I modified the main loop to check, that it's ok to play the song
void loop(){
// if the sensor is calibrated
if ( calibrated() ){
if ( trigOK() )
{
// get the data from the sensor
readTheSensor();
// report it out, if the state has changed
reportTheData();
}
}
}
// The bool trigOK returns TRUE if, the time is between 7-11AM &
// the motion was never detected, or detected more than 3600 seconds ago.
bool trigOK() {
if (Time.hour()>=7 & Time.hour()<=11){
if (trigT==0) {
return cantrig;
} else if (trigT >= ( Time.now() -3600 )){
cantrig = FALSE;
return cantrig;
} else {
cantrig = TRUE;
return cantrig;
}
} else {
cantrig= FALSE;
return cantrig;
}
}
// Within the motion detected function, I added the ability to record trigT
if (pirState == LOW) {
// we have just turned on
Particle.publish("designingiot/s15/motion");
Particle.publish("song");
trigT = Time.now();
// Update the current state
pirState = HIGH;
setLED( pirState );
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .