A basic IoT starter project inspired by the colorful display of lighting effects around the holidays.
main.js
JavaScriptA simple node.js application intended to blink Green and Red Gpio LED's in an alternating "holiday inspired" pattern on the Intel based development boards such as the Intel(R) Galileo and Edison with Arduino breakout board.
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
A simple node.js application intended to blink Green and Red Gpio LED's in an alternating "holiday inspired" pattern on the Intel based development boards such as the Intel(R) Galileo and Edison with Arduino breakout board.
*/
var mraa = require('mraa'); //require mraa
console.log('MRAA Version: ' + mraa.getVersion()); //write the mraa version to the Intel XDK console
//istantiate green led
var myOnboardGLed = new mraa.Gpio(8); //Green LED hooked up to digital pin 8
myOnboardGLed.dir(mraa.DIR_OUT); //set Green LED's gpio direction to output
var ledGState = false; //Boolean to hold the state of Green Led
//instantiate red led
var myOnboardRLed = new mraa.Gpio(6); //Red LED hooked up to digital pin 6
myOnboardRLed.dir(mraa.DIR_OUT); //set Red LED's gpio direction to output
var ledRState = true; //Boolean to hold the state of Red Led
periodicGActivity(); //call the periodicGActivity function
periodicRActivity(); //call the periodicRActivity function
function periodicGActivity()
{
gLed(); //call green led function
}
function periodicRActivity()
{
rLed(); //call red led function
}
function gLed()
{
myOnboardGLed.write(ledGState?1:0); //if ledGState is true then write a '1' (high) otherwise write a '0' (low)
ledGState = !ledGState; //invert the ledGState
setTimeout(periodicGActivity,1000); //call the indicated periodicGActivity function after 1 second (1000 milliseconds)
}
function rLed()
{
myOnboardRLed.write(ledRState?1:0); //if ledRState is true then write a '1' (high) otherwise write a '0' (low)
ledRState = !ledRState; //invert the ledRState
setTimeout(periodicRActivity,1000); //call the periodicRActivity function after 1 second (1000 milliseconds)
}
Comments