int ledPin = D3;
int buttonPin = D5;
bool doButton = false;
void setup()
{
pinMode( buttonPin , INPUT_PULLUP);
pinMode( ledPin , OUTPUT ); // sets pin as output
Particle.subscribe( "buttonPressed2", handleButtonPressed );
}
void loop()
{
// find out if the button is pushed
// or not by reading from it.
int buttonState = digitalRead( buttonPin );
if( buttonState == LOW )
{
// turn the LED On
digitalWrite( ledPin, HIGH);
Particle.publish("buttonPressed");
delay(1000);
}else{
// otherwise
// turn the LED Off
digitalWrite( ledPin, LOW);
}
if( doButton == true ){
digitalWrite( ledPin, HIGH);
delay(1000);
doButton = false;
}
}
void handleButtonPressed( const char *event, const char *data)
{
doButton = true;
}
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. .