Skip to content

Instantly share code, notes, and snippets.

@Atlas7
Last active October 17, 2015 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Atlas7/0597cb7b189d5d66a700 to your computer and use it in GitHub Desktop.
Save Atlas7/0597cb7b189d5d66a700 to your computer and use it in GitHub Desktop.
Hardware Project: Simple Button-triggered LED

Like Master Wong says, "this move, basic and simple". (Simple Button-triggered LED device, made with: Intel Edison Board, Groove Button and LED, Intel XDK IoT Edition, NodeJS.).

See this YouTube Demo.

/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
// Leave the above lines for propper jshinting
//Type Node.js Here :)

// Board setup
// D5: Grove Button
// D2: Grove LED - Red

// Usage
// Press the button, the LED turn on! so basic and simple :)

// Load Grove module
var groveSensor = require('jsupm_grove');

// Create the button object using GPIO pin 5
var button = new groveSensor.GroveButton(5);

// Create the Grove LED object using GPIO pin 2
var led = new groveSensor.GroveLed(2);

// Read button input. If pressed - turn LED on. Otherwise, LED off.
function readButtonValue() {
    //console.log(button.name() + " value is " + button.value());    
    if (button.value() == 0) {
        led.off();
    }
    else {
        led.on();
    }
}
setInterval(readButtonValue, 10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment