Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var b = require('bonescript');
- var led = "P8_13";
- var state = 0;
- b.pinMode(led, 'out');
- b.pinMode('P8_19', b.INPUT);
- setInterval(checkPIR, 5000); // Checks the Sensor Every 5 Seconds
- function checkPIR(){
- b.digitalRead('P8_19', printStatus);
- };
- toggleLED = function() {
- state = state ? 0:1;
- b.digitalWrite(led, state);
- };
- timer = setInterval(toggleLED, 100);
- stopTimer = function() {
- clearInterval(timer);
- };
- function printStatus(x){
- if(x.value === 0){
- b.digitalWrite(state, 1);
- console.log("Motion!");
- }
- else{
- b.digitalWrite(led, 0);
- console.log
- }
- };
- // setTimeout(stopTimer, 10000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement