Last active
December 30, 2016 17:24
-
-
Save soundanalogous/927360b797574ed50e27 to your computer and use it in GitHub Desktop.
node.js example for StandardFirmataBLE with Arduino 101
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Make sure the Intel Curie Boards by Intel board package version 1.0.6 or higher is installed | |
* via the Arduino Boards Manager | |
* | |
* Compile and upload StandardFirmataBLE from the firmata/arduino master branch. | |
* | |
* To run, install the following modules: | |
* npm install ble-serial | |
* npm install firmata | |
* | |
* To run with logging run as: | |
* DEBUG=ble-serial node ble-firmata-test | |
* | |
* wiring: | |
* button to pin D2 | |
* button to pin A2 | |
* LED to pin D10 | |
* potentiometer to pin A0 | |
*/ | |
var BLESerialPort = require('ble-serial').SerialPort; | |
var Firmata = require('firmata').Board; | |
var bleConnection = new BLESerialPort(); | |
var board = new Firmata(bleConnection, {samplingInterval: 30}); | |
board.on("ready", function() { | |
console.log( | |
board.firmware.name + "-" + | |
board.firmware.version.major + "." + | |
board.firmware.version.minor | |
); | |
var state = 1; | |
var blinkPin = 10; | |
var dBtnPin = 2; | |
var aBtnPin = 16; | |
var lastVal = 0; | |
board.pinMode(dBtnPin, board.MODES.INPUT); | |
// use analog pin as digital pin | |
board.pinMode(aBtnPin, board.MODES.INPUT); | |
setInterval(function() { | |
board.digitalWrite(blinkPin, (state ^= 1)); | |
}, 500); | |
board.analogRead(0, function(val) { | |
if (val !== lastVal) { | |
console.log(val); | |
} | |
lastVal = val; | |
}); | |
board.digitalRead(dBtnPin, function (val) { | |
console.log("pin " + dBtnPin + " value: " + val); | |
}); | |
board.digitalRead(aBtnPin, function (val) { | |
console.log("pin " + aBtnPin + " value: " + val); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can i use in Arduino UNO?