Last active
August 23, 2018 19:31
-
-
Save soundanalogous/4c30f9bae23cedc015a5 to your computer and use it in GitHub Desktop.
johnny-five example for StandardFirmataBLE and 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
/* | |
* 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