Code for the dining table
int leverButton = D1;
int flag =0;
int flagNew = 0;
void setup()
{
pinMode(leverButton, INPUT_PULLUP);
Serial.begin(9600);
}
void loop()
{
int leverState;
leverState = digitalRead(leverButton);
if (leverState == 0){ //Knocked
flagNew = 1;
}
else{
flagNew = 0 ;
}
if (flagNew == flag){//state stays the same
/*Serial.println("NO CHANGE IN BUTTON STATE");*/
}
else{
if (flagNew == 1){//someone pushed the button
Particle.publish("diotthanku2");
Serial.println("EVENT PUBLISHED");
delay(5000);
}
else {//the state went back to unpushed
Serial.println("Knock stopped");
}
}
flag = flagNew;
}
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. .