int lightPin = D5;
int hallPin = D3;
int ledPin = D0;
int lightState = 0;
int previousLight = 0;
int hallState = 0;
int previousHall = 0;
void setup(){
pinMode(lightPin, INPUT);
pinMode(hallPin, INPUT);
pinMode(ledPin, OUTPUT);
Particle.variable("lightState", lightState);
Particle.variable("hallState", hallState);
}
void loop(){
lightState = digitalRead(lightPin);
hallState = digitalRead(hallPin);
if(lightState == HIGH && hallState == HIGH)
{
digitalWrite(ledPin, 1); //light and hall are same
if(previousLight == LOW || previousHall == LOW)
{
Particle.publish("bathroomState", "Occupied");
}
}
else{
digitalWrite(ledPin, 0);
}
previousLight = lightState;
previousHall = hallState;
}
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. .