Now that everything is connected, type the following program in Cloud9, save it as blinkExternalLED.js
and run. You should be able to see the LED blinking each second:
var b = require('bonescript'); var led = "P8_10"; var state = b.HIGH; var loopTime = 1000; var exitTime = 30000; b.pinMode(led, b.OUTPUT); b.digitalWrite(led, state); var loopTimer = setInterval(blink, loopTime); var exitTimer = setTimeout(exitProgram,exitTime); function blink() { if(state == b.LOW) state = b.HIGH; else state = b.LOW; b.digitalWrite(led, state); } function exitProgram() { b.digitalWrite(led,b.LOW); clearInterval(loopTimer); }
This is the exact same program that we did in the previous chapter except we put LED as string P8_10
here. We declared P8_10
pin direction as output using function pinMode()
. When our program does digitalWrite()
HIGH
on P8_10
pin, the processor puts 3.3V on that pin. The current starts flowing from P8_10
to P8_2
and the LED glows...