var express = require('express'), util = require('util'), five = require("johnny-five"), board = new five.Board(), app = express(), staticPath = __dirname + "/"; var motorRight, motorLeft, motorUp, motorDown, fire; board.on("ready", function() { motorRight = new five.Motor(9); motorLeft = new five.Motor(8); motorUp = new five.Motor(10); motorDown = new five.Motor(11); fire = new five.Motor(12); util.debug('init complete'); }); app.put('/motorRightOn', function(req,res) { motorRight.start(); console.log("right on") res.send(200); }); app.put('/motorRightOff', function(req,res) { motorRight.stop(); console.log("right off") res.send(200); }); app.put('/motorLeftOn', function(req,res) {
var Tessel = require('tessel-io'); var five = require('johnny-five'); var pizza = require('./order.config'); var config = require('./auth.config'); var pizzapi = require('pizzapi'); var twilioClient = require('twilio')(config.accountSid, config.autToken) var board = new five.Board({ io: new Tessel() }); board.on("ready", () => { // set up messaging service // set up pizza order service var led = new five.Led("a5") var button = new five.Button("a2"); button.on("press", () => { led.on() // init pizza order // request address from messaging and orderPizza() // set up response listener for address from message // on success order pizza }
var five = require("johnny-five"), board = new five.Board(); board.on("ready", function() { var ping = new five.Ping(7); ping.on("change", function( err, value ) { if (this.cm < 5) { console.log("STOP!!!!"); } else { console.log("."); } }); });
const config = require('config'); const logger = require('winston'); const five = require('johnny-five'); const board = new five.Board({ port: config.get('port'), }); const ANALOG_PIN = 0; board.on('ready', function() { // Assuming a sensor is attached to pin "A0" this.analogRead(ANALOG_PIN, function(value) { const voltage = value * (3300 / 1024); const celsiusValue = (voltage - 500) / 10; const farenValue = (celsiusValue * (9 / 5)) + 32; logger.log('info', `Analog: ${value}, C: ${celsiusValue.toPrecision(3)}, F: ${farenValue}`); }); });
// This program prints out device diagnostics. var five = require('johnny-five'), board var board = new five.Board(); // the pin the DS18B20 is connected on var pin = 2; // Don't do anything until the board is ready for communication. board.on('ready', function () { // This requires OneWire support using the ConfigurableFirmata var temperature_1 = new five.Temperature({ controller: "DS18B20", //address: 0x60630e7, // Probe A pin: pin, freq: 1000 }); /*var temperature_2 = new five.Temperature({ controller: "DS18B20", //address: 0x60598c0, // Probe B //pin: pin, bus_pos: 1, freq: 1000 });*/ // Announce all devices on bus temperature_1.once("data", function() { console.log('Address', this.address.toString(16)); }); /*temperature_2.once("data", function() {
var five = require("johnny-five"); var Edison = require("edison-io"); var board = new five.Board({ io: new Edison() }); board.on("ready", function() { var temp = new five.Thermometer({ pin: "A0", controller: "GROVE" }); this.loop(2000, function(){ console.log(temp); console.log("%d degC", Math.round(temp.celcius)); }); var led = new five.Led(13); led.blink(); console.log("board is working..."); });
/** * Board - REPL. Make functions available to REPL. * * (Can call these functions from command line after starting the program. * http://johnny-five.io/examples/repl/ * * Setup = LED inserted into GND and 13. Minus (short leg) inserted into 13. * * This script will make on() and off() functions available in the REPL: * >> on() // will turn on the LED * >> off() // will turn off the LED */ var five = require("johnny-five"); var board = new five.Board(); board.on("ready", function() { console.log("Ready event. REPL instance auto-initialized!"); var led = new five.Led(13); // Make these functions available to the the REPL instance via injection. this.repl.inject({ // Allow limited on/off control access to the LED instance from the REPL. on: function() { led.on(); }, off: function() { led.off(); } });
var five = require("johnny-five"); var delay = require("./delay"); var board = new five.Board(); var MODES; // needs to be assigned once the board is ready var motorPin = 9; board.on("ready", function() { MODES = board.firmata.MODES; this.pinMode(motorPin, MODES.PWM); this.loop(4500, function() { motorOnThenOffWithSpeed(); }); // motorAcceleration(); // outside of the loop }); var motorOnThenOffWithSpeed = function motorOnThenOffWithSpeed () { var onSpeed = 200; var onTime = 2500; var offSpeed = 50; var offTime = 1000; this.analogWrite(motorPin, onSpeed); delay(onTime); this.analogWrite(motorPin, offSpeed); delay(offTime); }.bind(board); var motorAcceleration = function motorAcceleration() {
var five = require('johnny-five'); var board = new five.Board(); //https://github.com/rwaldron/johnny-five/wiki/Motor#api board.on('ready', function() { var motor = new five.Motor(9); motor.start(200); board.wait(2000, function() { motor.stop(); board.wait(1000, function() { motor.start(200); }); }); })
// keyControl.js var keypress = require("keypress"); var Spark = require("spark-io"); var five = require("johnny-five"); var Sumobot = require("sumobot")(five); keypress(process.stdin); var board = new five.Board({ io: new Spark({ token: process.env.SPARK_TOKEN, deviceId: process.env.SPARK_DEVICE_ID }) }); board.on("ready", function() { console.log("Welcome to Sumobot Jr!"); // Initialize a new Sumobot. // - Left Servo is attached to pin D0 // - Right Servo is attached to pin D1 // - Speed set to 0.50 (half of max speed) // var bot = new Sumobot({ left: "D0", right: "D1", speed: 0.50 }); // Maps key names to bot methods
var five = require("johnny-five"); var Spark = require("spark-io"); var keypress = require("keypress"); // //Activate keypress code keypress(process.stdin); // Create Johnny-Five board connected via Spark var board = new five.Board({ io: new Spark({ token: '3adb56a3c47a00f4a7f791968da1af987ed0adef', deviceId: 'sickbot' }) }); //Servos variables before renaming var servosLeft, servosRight, servos; board.on("ready", function() { console.log("Alert, I am assemebling..."); //WHEELS servosLeft = new five.Servo({pin: 'D0', type: "continuous"}).stop(); servosRight = new five.Servo({pin: 'A0', type: "continuous"}).stop(); //Using Keypress to control wheels process.stdin.resume(); process.stdin.setEncoding("utf8"); process.stdin.setRawMode(true);
var five = require("johnny-five"); var Tessel = require("tessel-io"); var board = new five.Board({ io: new Tessel() }); board.on("ready", () => { var leds = new five.Leds(["a2", "a3", "a4", "a5", "a6", "a7"]); var index = 0; var step = 1; board.loop(100, () => { leds.off(); leds[index].on(); index += step; if (index === 0 || index === leds.length - 1) { step *= -1; } }); });
'use strict'; var VIDEODIR = '/media/pi/ROCHASMINI/'; var raspi = require('raspi-io'); var five = require('johnny-five'); var board = new five.Board({ io: new raspi(), repl: false }); var playlist; var omx = require('omxdirector'); var exec = require('child_process').exec; var state = 0; var released = 1; board.on('ready', function() { var child = exec("ls -1 "+VIDEODIR, function (error, stdout, stderr) { if( error || stderr ){ console.log('VIDEO DIR NOT FOUND'); return; } omx.setVideoDir( VIDEODIR ); playlist = stdout.toString().split('\n'); //omx.play( stdout.toString().split('\n') ); var button = new five.Button({pin: 'GPIO12', invert: true}); button.on("hold", function() { console.log("hold"); console.log( playlist ); if( released ) { released = !released; if( !state ) { omx.play( playlist );
var pixel = require("node-pixel"); var five = require("johnny-five"); var board = new five.Board(); board.on("ready", function() { var strip = new pixel.Strip({ data: 6, length: 24, board: this, controller: "FIRMATA", }); strip.on("ready", function() { strip.color("#ff0000"); strip.show(); }); });
var five = require("johnny-five"), board = new five.Board(); board.on("ready", function() { // Creates a piezo object and defines the pin to be used for the signal var piezo = new five.Piezo(2); var play = function(tempo) { // Plays a song piezo.play({ // song is composed by an array of pairs of notes and beats // The first argument is the note (null means "no note") // The second argument is the length of time (beat) of the note (or non-note) song: [ ["C4", 1 / 4], ["D4", 1 / 4], ["F4", 1 / 4], ["D4", 1 / 4], ["A4", 1 / 4], [null, 1 / 4], ["A4", 1], ["G4", 1], [null, 1 / 2], ["C4", 1 / 4], ["D4", 1 / 4], ["F4", 1 / 4], ["D4", 1 / 4], ["G4", 1 / 4], [null, 1 / 4], ["G4", 1], ["F4", 1],
board.wait(2000, function() { motor.stop(); board.wait(1000, function() { motor.start(200); }); });
//import weather-js var weather = require('weather-js'); //The child process lib allows us to execute command line options var exec = require('child_process').exec; //This variable stores the command we want to execute var say = 'say '; //create new J5 board and LCD var five = require("johnny-five"), board, lcd; //create a new five board board = new five.Board(); //when the board is ready board.on("ready", function() { //configure the j5 LCD lcd = new five.LCD({ // LCD pin name RS EN DB4 DB5 DB6 DB7 // Arduino pin # 12 11 5 4 3 2 pins: [12, 11, 5, 4, 3, 2], backlight: 6, rows: 2, cols: 16 }); //Function to get weather and display on LCD function getWeather(){
var five = require("johnny-five"), // or "./lib/johnny-five" when running from the source board = new five.Board(); board.on("ready", function() { // Create an Led on pin 13 and strobe it on/off // Optionall set the speed; defaults to 100ms (new five.Led(13)).strobe(); });
/*global require:true module:true */ var five = require('johnny-five'); var board = new five.Board(); var openDoor, buildStatus; var goDoor = function () { var servo = new five.Servo({ pin: 10, range: [145, 180], startAt: 180 }); openDoor = function () { servo.min(); setTimeout(servo.max.bind(servo), 500); }; board.repl.inject({ servo: servo }); }; var goStatus = function () { var green = new five.Led(5); var red = new five.Led(5); var onVal = 100; buildStatus = function (good) { if (good) {
var five = require("johnny-five"); var board = new five.Board(); board.on("ready", function(){ var proximity = new five.Proximity({ controller: "HCSR04", pin: 7 }); proximity.on("data", function() { console.log("Proximity: "); console.log(" cm : ", this.cm); console.log(" in : ", this.in); console.log("-----------------"); }); proximity.on("change", function() { console.log("The obstruction has moved."); }); });
var five = require("johnny-five"); var http = require("http"); var board = new five.Board(); var led; board.on("ready", function() { led = new five.Led(13); var button = new five.Button(2); // Button Event API // "down" the button is pressed button.on("down", function() { console.log("down"); http.get("http://api.wunderground.com/api/b84113576c23be9c/conditions/q/UK/London.json", function(req) { // set encoding so this comes out as text instead of goop req.setEncoding('utf8'); req.on("data", function(data) { var pulseTime = 200; try { var obj = JSON.parse(data); //console.log(obj.response);
var five = require('johnny-five'); var board = new five.Board(); board.on('ready', function(){ // Set up LEDS var red = five.Led(9), green = five.Led(10), blue = five.Led(11); // Set up a scaled potentiometer var potentiometer = new five.Sensor({ pin: 'I2', freq: 100 }); potentiometer.scale(1, 10); // Set up the joystick var joystick = new five.Joystick({ pins: ['I0', 'I1'], freq: 100 }); // Set up a servo var servo = new five.Servo({ pin: 5 }); // Listen for changes potentiometer.on('read', function(err, value){ //green.brightness(this.normalized);
var five = require('johnny-five'), board = new five.Board(), PORT = 8080, WebSocketServer = require('ws').Server, request = require('request'), networkInterfaces = require('os').networkInterfaces(), motors = {}, led = {}, webappURL = 'http://10.0.0.5:3000', localIP; var wss = new WebSocketServer({port: PORT}); // board setup board.on('ready', function() { motors = { left: new five.Motor({ pins: { pwm: 3, dir: 12 }, invertPWM: true }), right: new five.Motor({ pins: { pwm: 5, dir: 8 }, invertPWM: true }) };
var five = require("johnny-five"); var Particle = require("particle-io"); var board = new five.Board({ io: new Particle({ token: '[AccessToken]', deviceName: '[DeviceName]' }) }); board.on("ready", function() { console.log('ready'); var rightWheel = new five.Motor({ pins: { pwm: "D0", dir: "D4" }, invertPWM: true }); var leftWheel = new five.Motor({ pins: { pwm: "D1", dir: "D5" }, invertPWM: true }); var speed = 255; function reverse() { leftWheel.rev(speed); rightWheel.rev(speed); } function forward() {
const NUM_PIXELS = 100; const DATA_PIN = 6; var five = require("johnny-five"); var pixel = require("node-pixel"); var opts = {}; //opts.port = process.argv[2] || ""; opts.port = '/dev/cu.usbmodem1421'; var board = new five.Board(opts); var strip = null; board.on("ready", function() { console.log("Board ready, lets add light"); strip = new pixel.Strip({ pin: DATA_PIN, // # pin pixels connected to length: NUM_PIXELS, // number of pixels in the strip board: this, controller: "FIRMATA" }); strip.on("ready", function() { console.log("Strip ready, let's go"); strip.color('#000000'); strip.show(); //draw data to pixels here });
body: { "protocol": "v1", "checksum": "", "device" : deviceId, "at" : "now", "data" : { "brightness":0 } }, json: true, headers: { "carriots.apikey": key } }; var raspi = require('raspi-io'); var five = require("johnny-five"); var board = new five.Board({ io: new raspi() }); board.on("ready", function() { var virtual = new five.Board.Virtual( new five.Expander("PCF8591") ); var a = new five.Sensor({ pin:"A0", board:virtual, freq: 10000 }); a.on("data", function() { options.body.data.brightness = this.value; console.log(this.value); // データをPOSTメソッドで送信 request.post(options, function(error, response, body){
var five = require("johnny-five"); // Load the node library that lets us talk JS to the Arduino var board = new five.Board(); // Connect to the Arduino using that library board.on("ready", function() { // Once the computer is connected to the Arduino // Save convenient references to the LED pin and an analog pin var LEDpin = new five.Pin(13); var analogPin = new five.Pin('A0'); var express = require('express'); // Load the library we'll use to set up a basic webserver var app = express(); // And start up that server app.get('/', function(req, res) { // what happens when we go to `/` res.send("Hello from `server.js`!"); // Just send some text }); app.get('/hello', function(req, res) { // what ha1ppens when we go to `/hello` res.sendFile('hello.html', { root: '.' }); // Send back the file `hello.html` located in the current directory (`root`) }); app.get('/:pin/state', function(req, res) { // what happens when someone goes to `/#/state`, where # is any number console.log("Someone asked for the state of pin", req.params.pin + "…"); var pins = { 'analog': analogPin, 'led': LEDpin }; if (pins.hasOwnProperty(req.params.pin)) { // If our pins dictionary knows about the pin name requested pins[req.params.pin].query(function(state) { // Look up the pin object associated with the pin name and query it res.send(state); // sending back whatever the state we get is }); } else {
// ======================= // Sumobot Jr demo program // ======================= var five = require("johnny-five"); var keypress = require('keypress'); var STOPVAL = 88; keypress(process.stdin); var board = new five.Board(); board.on("ready", function() { console.log("Welcome to Sumobot Jr!") console.log("Control the bot with the arrow keys, and SPACE to stop.") var left_wheel = new five.Servo({ pin: 9, type: 'continuous' }).move(STOPVAL); var right_wheel = new five.Servo({ pin: 10, type: 'continuous' }).move(STOPVAL); process.stdin.resume(); process.stdin.setEncoding('utf8'); process.stdin.setRawMode(true); process.stdin.on('keypress', function (ch, key) { if ( !key ) return;
var five = require('johnny-five'), board = new five.Board(); board.on('ready', function () { this.pinMode(12, five.Pin.PWM); this.analogWrite(12, 255); });
var five = require('johnny-five'); var board = new five.Board(); var led; var button1; var button2; var servo; var position = 90; board.on('ready', function() { console.log('ready!'); console.log('ready!'); led = new five.Led(2); button1 = new five.Button(4); button2 = new five.Button(7); [button1, button2].forEach(function(button) { button.on("hold", function() { led.on(); }); button.on("up", function() { led.off(); }) }); // Create a new `servo` hardware instance. servo = new five.Servo({