Skip to content

Instantly share code, notes, and snippets.

@soundanalogous
Last active August 23, 2018 19:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soundanalogous/4c30f9bae23cedc015a5 to your computer and use it in GitHub Desktop.
Save soundanalogous/4c30f9bae23cedc015a5 to your computer and use it in GitHub Desktop.
johnny-five example for StandardFirmataBLE and Arduino 101
/*
* To run, install the following modules:
* npm install ble-serial
* npm install johnny-five
*
* wiring:
* button to pin D2
* button to pin A2
* LED to pin D10
* potentiometer to pin A0
*/
var BLESerialPort = require('ble-serial').SerialPort;
var five = require('johnny-five');
//use the virtual serial port to send a command to a firmata device
var bleSerial = new BLESerialPort();
var board = new five.Board({port: bleSerial, repl: false});
board.on("ready", function() {
var lastVal = 0;
var led = new five.Led(10);
led.blink(500);
var btnD = new five.Button(2);
btnD.on("down", function () {
console.log("button 2 down");
});
var btnA = new five.Button("A2");
btnA.on("down", function () {
console.log("button A2 down");
});
var pot = new five.Sensor({
pin: "A0"
});
pot.on("data", function () {
if (this.raw !== lastVal) {
console.log(this.raw);
}
lastVal = this.raw;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment