Advertisement
silver2row

BoneScript, PIR, LED, and Timer

Jun 25th, 2019
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var b = require('bonescript');
  2. var led = "P8_13";
  3. var state = 0;
  4.  
  5. b.pinMode(led, 'out');
  6. b.pinMode('P8_19', b.INPUT);
  7.  
  8. setInterval(checkPIR, 5000); // Checks the Sensor Every 5 Seconds
  9.  
  10. function checkPIR(){
  11. b.digitalRead('P8_19', printStatus);
  12. };
  13.  
  14. toggleLED = function() {
  15.     state = state ? 0:1;
  16.     b.digitalWrite(led, state);
  17. };
  18.  
  19. timer = setInterval(toggleLED, 100);
  20.  
  21. stopTimer = function() {
  22.     clearInterval(timer);
  23. };
  24.  
  25. function printStatus(x){
  26.     if(x.value === 0){
  27.         b.digitalWrite(state, 1);
  28.     console.log("Motion!");
  29.     }
  30.     else{
  31.         b.digitalWrite(led, 0);
  32.     console.log
  33.     }
  34. };
  35.  
  36. // setTimeout(stopTimer, 10000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement