How to use johnny-five - 10 common examples

To help you get started, we’ve selected a few johnny-five examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rachelnicole / robokitty / lib / device.js View on Github external
board.on('ready', function() {

      var servo = new five.Servo({
        pin: 'd0',
        type: 'continuous',
        deadband: [ 95, 96 ]
      });

      servo.stop();

      io.sockets.on('connection', function (socket) {
        console.log('sockets on connection');

        socket.emit('setSchedule', currentTimeValue);

        socket.on('click', function () {
          console.log('socket is on');

          // have servo turn counter clockwise incase any food is stuck before turning clockwise to dispense
github sayanee / talks / web-sensors / code / minihack / index.js View on Github external
// code and wiring the breadboard
// http://johnny-five.io/examples/potentiometer/

var port = 8000
var five = require('johnny-five')
var board = new five.Board()
var potentiometer
var express = require('express')
var app = express().use(express.static('public'))
var server = app.listen(port, function () {
  console.log('App running on ' + port)
})
var io = require('socket.io').listen(server)

board.on('ready', function() {
  var sockets = []

  potentiometer = new five.Sensor({
    pin: 'A2',
    freq: 1000 // get the sensor value per milliseconds
  })
github ThingLabsIo / IoTLabs / Photon / Lab06 / lab06_light.js View on Github external
protocol: process.env.PROTOCOL || 'https',
    api_key: process.env.API_KEY || 'YOUR API KEY HERE'
};
config.store = new Store(config);
service = new nitrogen.Service(config);

// Create a new Nitrogen device for the photoresistor
// This device will send data it reads from a sensor
indicatorLight = new nitrogen.Device({
    nickname: 'lab06_indicatorLight',
    name: 'Lab 06 Indicator Light',
    tags: ['sends:_intensity', 'executes:_lightLevel']
});

// Define the Johnny Five board as your Particle Photon
board = new five.Board({
  io: new particle({
    token: process.env.PARTICLE_KEY || 'YOUR API KEY HERE',
    deviceId: process.env.PARTICLE_DEVICE || 'YOUR DEVICE ID OR ALIAS HERE'
  })
});

var LEDPIN = "D0";

// Define a command tag that you can scope to.
// This will enable you to filter to only relevant messages
var cmdTag = 'lab06';

// Connect the indicatorLight device defined above
// to the Nitrogen service instance.
service.connect(indicatorLight, function(err, session, indicatorLight) {
    if (err) { return console.log('Failed to connect lab06_indicatorLight: ' + err); }
github ThingLabsIo / IoTLabs / Photon / Weather / weather.js View on Github external
// Create the client instanxe that will manage the connection to your IoT Hub
// The client is created in the context of an Azure IoT device.
var client = Client.fromConnectionString(connectionString, Protocol);
// Extract the Azure IoT Hub device ID from the connection string 
// (this may not be the same as the Photon device ID)
var deviceId = device.ConnectionString.parse(connectionString).DeviceId;
console.log("Device ID: " + deviceId);

// Create a Johnny-Five board instance to represent your Particle Photon
// Board is simply an abstraction of the physical hardware, whether is is a 
// Photon, Arduino, Raspberry Pi or other boards. 
// When creating a Board instance for the Photon you must specify the token and device ID
// for your Photon using the Particle-IO Plugin for Johnny-five.
// Replace the Board instantiation with the following:
var board = new five.Board({
  io: new Particle({
    token: token,
    deviceId: 'YOUR PARTICLE PHOTON DEVICE IS OR ALIAS'
  })
});

// The board.on() executes the anonymous function when the 
// board reports back that it is initialized and ready.
board.on("ready", function() {
    console.log("Board connected...");
    
    // Open the connection to Azure IoT Hub
    // When the connection respondes (either open or error)
    // the anonymous function is executed
    client.open(function(err) {
        console.log("Azure IoT connection open...");
github ThingLabsIo / IoTLabs / Photon / Lab06 / lab06_light.js View on Github external
board.on("ready", function() {
        console.log("Board connected...");
           
        // Initialize the LED
        led = new five.Led(LEDPIN);
   
        // Inject the `sensor` hardware into the Repl instance's context;
        // Allows direct command line access
        board.repl.inject({
            led:led
        });
    });
});
github sayanee / talks / web-sensors / code / 2-ldr.js View on Github external
board.on('ready', function() {
  photoresistor = new five.Sensor({
    pin: 'A2', // connect to analog pin A2
    freq: 250 // the value will be read every 250 milli seconds
  })

  board.repl.inject({
    pot: photoresistor
  })

  photoresistor.on('data', function() {
    console.log(this.value)
    // hover your finger above the LDR - do you see the values changing?
    // can you bring this value to the frontend in the browser with Web Sockets?
  })
})
github mgold / Elm-Robotics / server.js View on Github external
board.on("ready", function() {
    // my robot has two motors and a proximity sensor
    // change pins and add other Johnny-Five devices as necessary
    var left = new five.Motor([5,4])
    var right = new five.Motor([6,7])
    var proximity = new five.Sensor("A0");

    left.brake();
    right.brake();

    io.sockets.on('connection', function (socket) {
        //The connection event fires every time the webpage is reloaded
        //So that fixes any problem of the ready callbacks being out of order

        proximity.on("data", function(){
            socket.emit("proximity", this.value);
        })

        socket.on('control', function (control) {
            if (control["enabled"]){
                if (control["drive"][0] > 0){
                    left.rev(threshhold(control["drive"][0]));
github AnnaGerber / little-bits-js / brightness / brightness.js View on Github external
board.on("ready", function() {
  
  led = new five.Led(5);

  dimmer = new five.Sensor({
    pin: "A0",
    freq: 250
  });
  
  led.on();

  dimmer.on("change", function() {
    // raw value read will be between 0 and 1023
    console.log("dimmer reading " + this.raw);
    // brightness expects a value up to 255, so divide by 4
    led.brightness(Math.floor(this.raw / 4));
  });

});
github rwaldron / particle-io / eg / servo.js View on Github external
board.on("ready", function() {
  console.log("CONNECTED");

  // Create a new `servo` hardware instance.
  var servo  = new five.Servo("D0");

  temporal.queue([
    {
      delay: 0,
      task: function(){
        // min()
        //
        // set the servo to the minimum degrees
        // defaults to 0
        //
        servo.min();
      }
    },{
      delay: 1000,
      task: function(){
        // max()
github intel / intel-iot-services-orchestration-layer / node_modules / hope-demo / lattepanda / init.js View on Github external
function stopServo(params){
  
  // parse params, params[0] should be "set_digital"
  var pinNumber = params[1];
  
  var servo = servos[pinNumber];
  
  if (servo == null) {
    log("creating new servo " + pinNumber);
    try{
      servo = new five.Servo(pinNumber);
      servos[pinNumber] = servo;
      
    } catch (err) {
      dir(err);
      log(err.stack.split("\n"));
      
    }
  }

  log("servoNumber %d stop", pinNumber);

  servo.stop();

  pinWrites[pinNumber].mode = MODE_SERVO;
  pinReads[pinNumber] = servo.value;

johnny-five

The JavaScript Robotics and Hardware Programming Framework. Use with: Arduino (all models), Electric Imp, Beagle Bone, Intel Galileo & Edison, Linino One, Pinoccio, pcDuino3, Raspberry Pi, Particle/Spark Core & Photon, Tessel 2, TI Launchpad and more!

MIT
Latest version published 3 years ago

Package Health Score

56 / 100
Full package analysis