NodeRover kits for NodeBots day Brisbane
Build instructions are here: https://t.co/x3J8mI0ddU
NodeRover kits for NodeBots day Brisbane
Build instructions are here: https://t.co/x3J8mI0ddU
| var five = require("johnny-five"); | |
| var myBoard, d1,d2,d3,d4; | |
| myBoard = new five.Board(); | |
| myBoard.on("ready", function() { | |
| d1 = new five.Led(13); | |
| d2 = new five.Led(12); | |
| d3 = new five.Led({pin:11, isAnode: true}); | |
| d4 = new five.Led({pin:10, isAnode: true}); | |
| d3.off(); | |
| d4.off(); | |
| d1.strobe( 1000 ); | |
| // make myLED available as "led" in REPL | |
| // try "on", "off", "toggle", "strobe", "stop" (stops strobing) | |
| this.repl.inject({ | |
| d1: d1, | |
| d2: d2, | |
| d3: d3, | |
| d4: d4 | |
| }); | |
| console.log("You can interact with the LED via the variable 'led' e.g. led.on();\n Hit control-D to exit.\n >> "); | |
| }); |
| var five = require("johnny-five"); | |
| var exports = {}; | |
| // override noTone function so that it sets HIGH instead of LOW | |
| // (this is inverted because of the way that piezo is wired up with 10K resistor to 5V) | |
| five.Piezo.prototype.noTone = function() { | |
| this.io.digitalWrite(this.pin, 255); | |
| if (this.timer) { | |
| this.timer.clearInterval(); | |
| delete this.timer; | |
| } | |
| return this; | |
| }; | |
| exports.five = five; | |
| module.exports = exports; |
| var five = require("johnny-five"), | |
| board, myPhotoresistor, myLed; | |
| board = new five.Board(); | |
| board.on("ready", function() { | |
| //myLed = new five.Led(9); | |
| myPhotoresistor = new five.Sensor({ | |
| pin: "A4", | |
| freq: 250 | |
| }); | |
| myPhotoresistor.on("data", function( err, value ) { | |
| console.log("light", value) | |
| // range of led brightness is 0 - 255 | |
| var brightnessValue = five.Fn.constrain(five.Fn.map(value, 0, 900, 0, 255), 0, 255); | |
| //myLed.brightness(brightnessValue); | |
| }); | |
| }); |
| { | |
| "name": "nbd2015", | |
| "version": "1.0.0", | |
| "description": "johnny-five code examples to work with HCARDU0085 expansion board for Arduino Uno", | |
| "author": "Anna Gerber", | |
| "license": "MIT", | |
| "dependencies": { | |
| "async": "^1.4.0", | |
| "johnny-five": "^0.8.81", | |
| "keypress": "^0.2.1", | |
| "lodash": "^3.10.0" | |
| } | |
| } |
| var eb = require("./expansion-board.js"), | |
| five = eb.five, | |
| board, piezo; | |
| board = new five.Board(); | |
| board.on("ready", function() { | |
| piezo = new five.Piezo(3); | |
| function playSong() { | |
| piezo.play({ | |
| // song is composed by a string of notes | |
| // a default beat is set, and the default octave is used | |
| // any invalid note is read as "no note" | |
| song: "C D F D A - A A A A G G G G - - C D F D G - G G G G F F F F - -", | |
| beats: 1 / 4, | |
| tempo: 100 | |
| }); | |
| } | |
| playSong(); | |
| board.repl.inject({ | |
| piezo: piezo, | |
| playSong: playSong | |
| }); | |
| console.log("Try piezo.tone(160,100) or piezo.noTone() or playSong()\nHit control D to exit\n>>"); | |
| }); |
| var five = require("johnny-five"); | |
| var myBoard, ping; | |
| myBoard = new five.Board(); | |
| myBoard.on("ready", function() { | |
| ping = new five.Proximity({ | |
| controller: "HCSR04", | |
| pin: 9 | |
| }); | |
| ping.on("data", function() { | |
| console.log("inches: ", this.inches); | |
| console.log("cm: ", this.cm); | |
| }); | |
| }); | |
| var five = require("johnny-five"), | |
| board, myPotentiometer; | |
| board = new five.Board(); | |
| board.on("ready", function() { | |
| myPotentiometer = new five.Sensor({ | |
| pin: "A0", | |
| freq: 500 | |
| }); | |
| myPotentiometer.on("data", function(err,data) { | |
| console.log(data); | |
| }); | |
| }); | |
| var eb = require("./expansion-board.js"), | |
| five = eb.five; | |
| var board = new five.Board(); | |
| board.on("ready", function() { | |
| /* | |
| This assumes the segments are as follows: | |
| A | |
| --- | |
| F | | B | |
| --- <---- G | |
| E | | C | |
| --- | |
| D o DP | |
| */ | |
| var isCommonAnode = true; | |
| var digits = [ | |
| // .GFEDCBA | |
| parseInt("00111111", 2), | |
| parseInt("00000110", 2), | |
| parseInt("01011011", 2), | |
| parseInt("01001111", 2), | |
| parseInt("01100110", 2), | |
| parseInt("01101101", 2), | |
| parseInt("01111101", 2), | |
| parseInt("00000111", 2), | |
| parseInt("01111111", 2), | |
| parseInt("01101111", 2), | |
| ]; | |
| var segments = { | |
| // .GFEDCBA | |
| a: parseInt("00000001", 2), | |
| b: parseInt("00000010", 2), | |
| c: parseInt("00000100", 2), | |
| d: parseInt("00001000", 2), | |
| e: parseInt("00010000", 2), | |
| f: parseInt("00100000", 2), | |
| g: parseInt("01000000", 2), | |
| dp: parseInt("10000000", 2) | |
| }; | |
| var piezo = new five.Piezo(3); | |
| piezo.noTone() | |
| var register = new five.ShiftRegister({ | |
| pins: { | |
| data: 8, | |
| clock: 7, | |
| latch: 4 | |
| } | |
| }); | |
| function invert(num) { | |
| return ((~num << 24) >> 24) & 255; | |
| } | |
| function digit(num) { | |
| clear(); | |
| register.send( | |
| isCommonAnode ? invert(digits[num]) : digits[num] | |
| ); | |
| } | |
| function segment(s) { | |
| clear(); | |
| register.send( | |
| isCommonAnode ? invert(segments[s]) : segments[s] | |
| ); | |
| } | |
| function clear() { | |
| register.send( | |
| isCommonAnode ? 255 : 0 | |
| ); | |
| } | |
| var i = 9; | |
| function next() { | |
| digit(i--); | |
| if (i < 0) { | |
| i = 9; | |
| setTimeout(next, 2000); | |
| } else { | |
| setTimeout(next, 1000); | |
| } | |
| } | |
| //next(); | |
| segment("a"); | |
| }); |
| var five = require("johnny-five"); | |
| var board = new five.Board(); | |
| board.on("ready", function() { | |
| var temp = new five.Temperature({ | |
| pin: "A4", | |
| controller: "LM35", | |
| freq: 1000 | |
| }); | |
| temp.on("data", function(err, data) { | |
| // value: function(raw) { | |
| // return (5.0 * raw * 100.0)/1024.0; | |
| // } | |
| console.log("data",data) | |
| //console.log("Temp: %d", data.celsius); | |
| //console.log(data.celsius + "°C", data.fahrenheit + "°F"); | |
| }); | |
| }); | |