Back to Parent

void loop()
{
    
    //Stores the value output by the PIR based on whether or not
    //It detects motion by reading the PIR pin.
    int currentMotion = digitalRead (PIRpin);
    
    //If there is motion the global variable motion is set to true
    if (currentMotion==HIGH){
      motion = true;
    }
    //Otherwise set the global variable motion is set to false
    else{
      motion = false;
    }
    
    //wait a little
    delay(100);
}

/*...*/

void checkReaction(String data){
    
    delay(3000);
    if(motion==true){
        //Publish an event to indicate that there was a motion 
        //based reaction and the first bus stop. The tweet data
        //is published as the data, while "reaction" is the 
        //event name
        publishEvent("Reaction", data);
    }
    else{
        //Publish an event to indicate that there was not a 
        //motion based reaction and the first bus stop and there 
        //is no data in the event 
        publishEvent("NoReaction", "");
    }
    //pulse the lights onece
    pulse();
    //take a pause
    delay(1000);
    //publish the motion variable
    //this is more so to allow the developer or commissioned 
    //entity to know when the stop is triggered and if there was a reaction.
    publishEvent("Motion", (String)motion);
    
    
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0