If you executed the previous program a few times, you would have noticed that though the program is getting executed correctly, it does not exit by itself. It has an infinite loop of timer. So, it needs to be stopped manually. If the LED state is on at the time of stopping the program, it will remain on later. Let's add a new timer that will trigger after a minute to exit the program and turn off the USER3 LED if it is on. Also, let's change the hard-coded values that we used in the previous program. Type the following program in Cloud9, save it as blinkOnboardLED2.js
, and run it. The program should stop automatically after a minute with the USER3 LED always off. The code for blinkOnboardLED2.js
is as follows:
var b = require('bonescript'); var led = "USR3"; var loopTime = 1000; var exitTime = 60000; var state = b.HIGH; b.pinMode(led, b.OUTPUT); b.digitalWrite(led, state); var loopTimer = setInterval(blink, loopTime); setTimeout(exitProgram,exitTime); function blink...