Skip to content

Instantly share code, notes, and snippets.

@soundanalogous
Last active December 30, 2016 17:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soundanalogous/927360b797574ed50e27 to your computer and use it in GitHub Desktop.
Save soundanalogous/927360b797574ed50e27 to your computer and use it in GitHub Desktop.
node.js example for StandardFirmataBLE with Arduino 101
/*
* 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);
});
});
@TomasPangzi
Copy link

Can i use in Arduino UNO?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment