User Tools

Site Tools


oak:tutorials:pir

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Last revision Both sides next revision
oak:tutorials:pir [2016/08/13 12:47]
brohan
oak:tutorials:pir [2016/08/14 13:59]
mstolt [Code] Formatting
Line 114: Line 114:
  
   //give the sensor some time to calibrate   //give the sensor some time to calibrate
-    ​for(int i = 0; i < calibrationTime;​ i++){ +  ​for(int i = 0; i < calibrationTime;​ i++){ 
-      delay(10000); +    delay(10000);​
-      } +
-    delay(50);+
   }   }
 +  delay(50);
 +
 +}
  
 void loop(){ void loop(){
  
-     if(digitalRead(pirPin) == HIGH){ +  ​if(digitalRead(pirPin) == HIGH){ 
-       ​digitalWrite(ledPin,​ HIGH); +    digitalWrite(ledPin,​ HIGH); 
-       ​Particle.publish("​MOTION SENSOR",​ "​Motion detected"​);​ +    Particle.publish("​MOTION SENSOR",​ "​Motion detected"​);​ 
-         ​if(lockLow){ ​  +    if(lockLow){ ​  
-         ​lockLow = false; ​            +      lockLow = false; ​            
-         ​delay(1000);​ +      delay(1000);​ 
-         ​}          +    }          
-         ​takeLowTime = true; +    takeLowTime = true; 
-       ​}+  }
  
-     if(digitalRead(pirPin) == LOW){        +  ​if(digitalRead(pirPin) == LOW){        
-       ​digitalWrite(ledPin,​ LOW);  ​+    digitalWrite(ledPin,​ LOW);  ​
  
-       if(takeLowTime){ +    ​if(takeLowTime){ 
-        lowIn = millis(); ​      +      lowIn = millis(); ​      
-        takeLowTime = false; ​      +      takeLowTime = false; ​      
-        }+    }
  
-       if(!lockLow && millis() - lowIn > pause){ ​  +    ​if(!lockLow && millis() - lowIn > pause){ ​  
-           ​//makes sure this block of code is only executed again after  +      //makes sure this block of code is only executed again after  
-           ​//a new motion sequence has been detected +      //a new motion sequence has been detected 
-           ​lockLow = true;                         +      lockLow = true;                         
-           ​delay(50);​ +      delay(50);​ 
-           ​+    
-       }+    
   }   }
 +
 +}
 +
 </​code>​ </​code>​
  
oak/tutorials/pir.txt · Last modified: 2017/01/16 22:53 by weaslyd