int inputPin = D0;
int ledPin = D1;
int pirState = LOW;
int val = 0;
int calibrateTime = 10000;
void setup()
{
pinMode( ledPin, OUTPUT );
pinMode(inputPin, INPUT);
}
void loop()
{
if ( calibrated() )
{
readTheSensor();
reportTheData();
}
}
void readTheSensor() {
val = digitalRead(inputPin);
}
bool calibrated() {
return millis() - calibrateTime > 0;
}
void reportTheData() {
if (val == HIGH) {
if (pirState == LOW) {
Particle.publish("designingiot/s15/motion");
pirState = HIGH;
setLED( pirState );
}
} else {
if (pirState == HIGH) {
pirState = LOW;
setLED( pirState );
}
}
}
void setLED( int state )
{
digitalWrite( ledPin, state );
}
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. .