Example #1
0
var raspi = require("raspi-io");
var five = require("johnny-five");

var board = new five.Board({
  io: new raspi()
});

board.on("ready", function() {
  var pin, state;

  pin = new five.Pin(7); // GPIO4

  this.loop(500, function() {
    pin.write( state ^= 0x01 );
  });
});
Example #2
0
var five = require('johnny-five');
var board = new five.Board();

board.on('ready', function(){
  
  // create LED pin
  var ledGreen = five.Led(3);
  var ledRed = five.Led(6);
  var ledYellow = five.Led(13)

  ledGreen.blink(1000);

  this.wait(1000, function(){
    ledRed.blink(1000)
  });

  console.log("Multiple lights");
});
Example #3
0
let led = []; 
let button;

const g_onpress = function(i) {
	return () => {
	console.log("Button pressed");
	led[i].on();
	}
}

const g_onrelease = function(i) {
	return () => {
	console.log("Button released");
	led[i].off();
	}
}

const onready = function() {
	led[0] = new five.Led(2);
	led[1] = new five.Led(3);
	led[2] = new five.Led(4);
	button = new five.Button(11);
	button.on("press", g_onpress(2));
	button.on("release", g_onrelease(2));
	// led[0].blink(30);
	this.repl.inject({ led, button });
}

board.on("ready", onready); 

Example #4
0
log.setLevel('TRACE');

const five = require("johnny-five");

// Create and initialize a board object

const serialPortName = "COM42";

const board = new five.Board({port: serialPortName, repl: false});
const componentController = require("./CTL_MCP9808");

// When the board is ready, start blinking the LED and then trigger the rest of the program to run

board.on("ready", function() {
  log.info(`Connected to ${board.io.firmware.name}-${board.io.firmware.version.major}.${board.io.firmware.version.minor}`);
  const led = new five.Led(13);
  led.blink(2000);
  board.emit("blinking");
});

// Once the light is blinking, we're ready to really start work

board.on("blinking", function () {
  let sensor = new five.Thermometer({
    controller: componentController.CTL_MCP9808,
    custom: {unit: "MCP9808:0", flags: 1},
    freq: 1000
  });

  sensor.on("data", function(data) {
    log.debug(`data event: ${data.C}°C, ${data.F}°F, ${data.K}°K.`);
  });
Example #5
0
var five = require('johnny-five'),
    board,led;

board = new five.Board();
board.on('ready', function(){
  led = new five.Led(13);
  led.strobe();

  this.repl.inject({
    led: led
  })
});
Example #6
0
var five = require("johnny-five");
var Spark = require("spark-io");
var board = new five.Board({
  io: new Spark({
    token: process.env.SPARK_TOKEN,
    deviceId: process.env.SPARK_DEVICE_ID
  })
});

board.on("ready", function() {
  motorL = new five.Motor({
    pin: 'A1'
  });

  motorR = new five.Motor({
    pin: 'A0'
  });

  board.repl.inject({
    l: motorL,
    r: motorR
  });

});
Example #7
0
board.on("ready", function() {
  //var motor = new five.Motor({pins: [2,3]});
  var leftMotorPin1 = new five.Pin(2);
  var leftMotorPin2 = new five.Pin( {pin:3,  type: "digital"});
  
  var rightMotorPin1 = new five.Pin( {pin:5,  type: "digital"});
  var rightMotorPin2 = new five.Pin( {pin:6,  type: "digital"});


  function moveBackwards(){
    leftMotorPin1.low();leftMotorPin2.high();
    rightMotorPin1.low();rightMotorPin2.high();
  }

  function moveForward(){
    leftMotorPin1.high();leftMotorPin2.low();
    rightMotorPin1.high();rightMotorPin2.low();
  }

  function left(){
    leftMotorPin1.high();leftMotorPin2.low();
    rightMotorPin1.high();rightMotorPin2.high();
  }

  function right(){
    leftMotorPin1.high();leftMotorPin2.high();
    rightMotorPin1.high();rightMotorPin2.low();
  }

  function brake(){
    leftMotorPin1.high();leftMotorPin2.high();
    rightMotorPin1.high();rightMotorPin2.high();
  }

  var led = new five.Led(8);
  led.blink(500);
  brake();

  this.repl.inject({
    led: led,
    forward: moveForward,
    back: moveBackwards,
    brake: brake,
    right: right,
    left, left
  });
});
Example #8
0
bot.on("ready", function() {

  console.log("Hit control-C to exit.\n >> ");

  // 9 is the pin #
  myLed = new j5.Led(9);

  myLed.off();

  bot.repl.inject({
    led: myLed
  });

  var count = 1;

  bot.loop(100, function() {

    // 1. Write code, functioning as:
    //    "S", on (100ms), off (100ms), on, off, on, off
    // 2. Write code, functioning as:
    //    "O", on (300ms), off (100ms), on, off, on, off
    // 3. Write code, functioning as:
    //    "S", on (100ms), off (100ms), on, off, on, off
    //    +off (100ms)
    //    "O", on (300ms), off (100ms), on, off, on, off
    //    +off (100ms)
    //    "S", on (100ms), off (100ms), on, off, on, off

  });

});
Example #9
0
'use strict'

const five = require("johnny-five")
const board = new five.Board();
let lcd = null
let ready = false

board.on("ready", function() {
  lcd = new five.LCD({
    pins: [7, 8, 9, 10, 11, 12],
    backlight: 6,
    rows: 2,
    cols: 20
  });

  this.repl.inject({
    lcd: lcd
  })

  ready = true
})


function writeMessage(message) {
  lcd.clear()
  lcd.print(message)
}

function onReady(callback) {
  let waitForReady = setInterval(() => {
    if(ready) {
Example #10
0
board.on("ready", function() {

  var heart = [
    "01100110",
    "10011001",
    "10000001",
    "10000001",
    "01000010",
    "00100100",
    "00011000",
    "00000000"
  ];

  var matrix = new five.Led.Matrix({ 
    controller: "HT16K33",
    isBicolor: true
  });

  matrix.clear();

  var msg = "johnny-five".split("");

  function next() {
    var c;

    if (c = msg.shift()) {
      matrix.draw(c);
      setTimeout(next, 500);
    }
  }

  next();

  this.repl.inject({
    matrix: matrix,
    heart: function() {
      matrix.draw(heart);
    }
  });
});
Example #11
0
board.on("ready", function() {
    var sensor1 = new five.Pin(8);
    var sensor2 = new five.Pin(9);
    
    // Read for sensor on PIN 8
    five.Pin.read(sensor1, function(error, value1) {
        if ((value1 == 1) && (!state1Changed)) {
            state1Changed = true;
            var sensors = [{  
                sensor1: true,
                sensor2: false}];
            
            console.log('Sensor1: ' + value1);
            io.sockets.emit('sensors', sensors);
        }

        if ((value1 == 0) && (state1Changed)) {
            state1Changed = false;
        }
    });

    // Read for sensor on PIN 9
    five.Pin.read(sensor2, function(error, value2) {
        if ((value2 == 1) && (!state2Changed)) {
            state2Changed = true;
            var sensors = [{  
                sensor1: false,
                sensor2: true}];

            console.log('Sensor2: ' + value2);
            io.sockets.emit('sensors', sensors);
        }

        if ((value2 == 0) && (state2Changed)) {
            state2Changed = false;
        }
    });
});
function setVolume(volume, done) {
  setTimeout(function() {
    cp.exec('sudo osascript -e "set Volume ' + volume + '"', done)
  }, 5000)
}

app.use(express.static(__dirname + '/public'))

var board = new five.Board()
var socket = null

function boardReady() {
  var BWAMMM = new five.Button({pin: 2})
  BWAMMM.on('down', function() {
    console.log('inception\'d')
    if (!socket) return
    socket.emit('next')
    cp.exec('afplay public/audio/inception.mp3', function() {
      console.log('done playing')
    })
  })
}

board.on('ready', boardReady)

io.sockets.on('connection', function(s) {
  socket = s
})

server.listen(1337)
board.on('ready', function () {
  /**
   *    * Playground Controllers
   *       */
  var accelerometer = new five.Accelerometer({
    controller: Playground.Accelerometer
  })

  var pixels = new five.Led.RGBs({
    controller: Playground.Pixel,
    pins: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  })

  var pads = new five.Touchpad({
    controller: Playground.Touchpad,
    pads: [0, 10]
  })

  var piezo = new five.Piezo({
    controller: Playground.Piezo,
    pin: 5
  })

  var thermometer = new five.Thermometer({
    controller: Playground.Thermometer,
    freq: 100
  })

  /**
   *    * Default Component Controllers
   *       * @type {five}
   *          */
  var buttons = new five.Buttons([4, 19])

  var led = new five.Led(13)

  var light = new five.Sensor({
    pin: 'A5',
    freq: 100
  })

  var sound = new five.Sensor({
    pin: 'A4',
    freq: 100
  })

  // var toggle = new five.Switch(21)

  /**
   *    * Events and Data Handling
   *       */
  accelerometer.on('tap', (data) => {
    piezo.frequency(data.double ? 1500 : 500, 50)
  })

  board.loop(1000, () => {
    console.log('Raw Light: %d', light.value)
    console.log('Raw Sound: %d', sound.value)
  })

  buttons.on('press', (button) => {
    console.log('Which button was pressed? ', button.pin)
    if (button.pin === 4) {
      led.on()
    }
    if (button.pin === 19) {
      led.off()
    }
  })

  thermometer.on('change', (data) => {
    console.log('Celcius: %d', data.C)
  })

  pads.on('change', (data) => {
    if (data.type === 'down') {
      piezo.frequency(700, 50)
    } else {
      piezo.noTone()
    }
  })

  var index = 0
  var colors = [
    'red',
    'orange',
    'yellow',
    'green',
    'blue',
    'indigo',
    'violet'
  ]

  setInterval(() => {
    pixels.forEach(pixel => pixel.color(colors[index]))
    if (++index === colors.length) {
      index = 0
    }
  }, 100)
})
Example #14
0
// Turn on LED with Tessel 2

var five = require('johnny-five');
	Tessel = require('tessel-io');
	board = new five.Board({
		io: new Tessel()
	});

board.on("ready", () => {
	var led = new five.Led("a5");

	
	//led.on();
	//led.blink(2500)
	led.blink();
})

Example #15
0
board.on("ready", function() {
    var leds = [
        new five.Led({pin:7}),
        new five.Led({pin:8}),
        new five.Led({pin:9}),
        new five.Led({pin:10}),
        new five.Led({pin:11}),
        new five.Led({pin:12})
    ];

    var sensor = new five.Sensor({
        pin: "A5",
        freq: 250
    });

    board.repl.inject({
        sensor: sensor
    });

    sensor.on("read", function(err, value) {
        var level = this.normalized * 7 / 255 - 1;
        console.log( value, this.normalized, level );
        for (var i=0; i <= 5; i++) {
            if (level > i) {
                leds[i].on();
            } else {
                leds[i].off();
            }
        }
    });
});
/**
 * Potential Button Solution - Code
 * http://acingraham.github.io/reveal.js/#/57/4
 */
 
var five = require("johnny-five");
var board = new five.Board();

board.on("ready", function() {
  var servo = new five.Servo(11);
  var button = new five.Button(2);

  button.on("press", function() {
    servo.sweep();
  });

  button.on("release", function() {
    servo.stop();
  });
});
Example #17
0
var raspi = require('raspi-io');
var five = require('johnny-five');
var board = new five.Board({
  io: new raspi()
});

board.on('ready', function() {

  // Create an Led on pin 7 (GPIO4) on P1 and strobe it on/off
  // Optionally set the speed; defaults to 100ms
  (new five.Led('P1-7')).strobe();

});

var five = require('johnny-five');
var board = new five.Board();

board.on('ready', function () {
  var led = new five.Led(13);
  led.blink(500);
});
  // Make the actual call to the LED
  five.Led.prototype[method].apply(led, args);

  // Increment the step
  step++;

  // If we're at the end, start over (loop==true) or exit
  if (step === demoSequence.length) {
    if (loop) {
      step = 0;
    } else {
      // We're done!
      process.exit(0);
    }
  }

  // Recursively call the next step after specified duration
  board.wait(duration, function() {
    execute(step);
  });
}

board.on("ready", function() {
  // Defaults to pin 11 (must be PWM)
  led = new five.Led(5);

  // Kick off the first step
  execute(0);
});
Example #20
0
var five = require("johnny-five"),
    board = new five.Board(),
    myLed;

board.on("ready", function() {

  myLed = new five.Led({
    pin: 13 
  });

  myLed.strobe();

  // Hacemos que este disponible el objeto "myLed" dentro del REPL
  this.repl.inject({
      led: myLed
  });
  console.log( 'ready!' );

});
const five = require('johnny-five'),
  board = new five.Board();

board.on('ready', () => {
  const servo = new five.Servo(11);
  let isMax = false;
  setInterval(() => {
    isMax = !isMax;
    if(isMax) servo.to(180);
    else servo.to(0)
  }, 1000);
});
var board = new five.Board();

const msCount = 1000;

var leds;
var currentLed;

board.on("ready", function() {
  var self = this;

  var led4 = new five.Led(4);
  var led6 = new five.Led(6);
  var led7 = new five.Led(7);
  var led2 = new five.Led(2);

  led4.off();
  led6.off();
  led7.off();
  led2.off();

  leds = [led4, led6, led7, led2];

  upLed(led4, self);
});

function upLed(led, cont) {
  currentLed = led;

  led.on();

  led.blink();
Example #23
0
var j5 = require("johnny-five");
//var myBoard = new j5.Board({port: "/dev/tty.usbserial-A9GF3L9D" });
var myBoard = new j5.Board();
myBoard.on("ready", function() {
  var myLed = new j5.Led.RGB([ 9, 10, 11 ]);
  // make the LED red
  myLed.color("#ff0000");
  this.wait( 1000, function() {
    // make the LED blue after 1 second
    myLed.color("#00ff00");
  });
  this.wait(2000, function(){
    // make the LED green after 2 seconds
    myLed.color("#0000ff");
  });
  this.wait(3000, function(){
    // turn the LED off after 3 seconds
    myLed.off();
  });
  this.repl.inject({
    r: myLed
  });
});
Example #24
0
board.on("ready", function() {

// Create a new `motion` hardware instance.
  var motion = new five.Motion(7);
  led = new five.Led(2);
 

  // Create a new `switch` hardware instance.
  // This example allows the switch module to
  // create a completely default instance
  toggleSwitch = new five.Switch(8);

  // Inject the `switch` hardware into
  // the Repl instance's context;
  // allows direct command line access
  board.repl.inject({
    toggleSwitch: toggleSwitch
  });

  // Switch Event API

  // "closed" the switch is closed
  toggleSwitch.on("close", function() {
    console.log("closed");
	
  // "motionend" events are fired following a "motionstart" event
  // when no movement has occurred in X ms
  motion.on("motionend", function() {
	    console.log("motionend", Date.now());
	    led.off();
	  });
  });


  // "open" the switch is opened
  toggleSwitch.on("open", function() {
    console.log("open");

	 // "calibrated" occurs once, at the beginning of a session,
	  motion.on("calibrated", function() {
	    console.log("calibrated", Date.now());
	  });

       // "motionstart" events are fired when the "calibrated"
      // proximal area is disrupted, generally by some form of movement
      motion.on("motionstart", function() {
	    led.on();
	    console.log("motionstart", Date.now());
  	});
  });

});
var io = require('socket.io').listen(8888),
	five = require( 'johnny-five' ),
	board = new five.Board(),
	light;
 
 
// The board's pins will not be accessible until
// the board has reported that it is ready
board.on("ready", function() {
	
	led = new five.Led(13);
	led.off();  
	light = false;

	io.sockets.on('connection', function (socket) {  
        socket.broadcast.emit('status', light );
	    
	    socket.on('status', function (data) {
	    	light = data;

			if(light) {
				led.on();
			}
			else
			{
				led.off();
			}
	    });
	}); 
});
Example #26
0
board.on("ready", function(err) {

    if (err){
        console.log(err);
        return;
    }

    console.info("Board connected. Robot set up");

    motor_r = new five.Motor({
        pins: {
            pwm: 9,
            dir: 8,
        },
        invertPWM: true,
    });

    motor_l = new five.Motor({
        pins: {
            pwm: 6,
            dir: 7,
        },
        invertPWM: true,
    });

	console.info("Robot running issue commands to it.");
	console.info("LRUD arrows. Space stop. C quit");

});
Example #27
0
board.on("ready", function() {

  // Motor 1
  // var motor = new five.Motor({
  //     pins: { pwm: 11 },
  //     register: { data: 8, clock: 4, latch: 12 },
  //     bits: { a: 2, b: 3 }
  //   }
  //  );
 
  // Motor 2
  var motor = new five.Motor({
      pins: { pwm: 3 },
      register: { data: 8, clock: 4, latch: 12 },
      bits: { a: 1, b: 4 }
    }
   );

  board.repl.inject({
    motor: motor
  });

  motor.on("start", function(err, timestamp) {
    console.log("start", timestamp);
  });

  motor.on("stop", function(err, timestamp) {
    console.log("automated stop on timer", timestamp);
  });

  motor.on("brake", function(err, timestamp) {
    console.log("automated brake on timer", timestamp);
  });

  motor.on("forward", function(err, timestamp) {
    console.log("forward", timestamp);

    // demonstrate switching to reverse after 5 seconds
    board.wait(5000, function() {
      motor.reverse(150);
    });
  });

  motor.on("reverse", function(err, timestamp) {
    console.log("reverse", timestamp);

    // demonstrate stopping after 5 seconds
    board.wait(5000, function() {

      // Apply the brake for 500ms and call stop()
      motor.brake(500);
    });
  });

  // Start the motor at maximum speed
  motor.forward(255);

});
var five = require("johnny-five")
  , board = new five.Board();

board.on("ready", function() {
  var leds = []
    , led;

  for(var i = 2; i <= 9; i++) {
    led = new five.Led(i);
    led.strobe(500);
    leds.push(led);
  }

  board.repl.inject({
    leds: leds
  });
});
board.on("ready", function() {

  // Create a new `sensor` hardware instance.
  sensor1 = new five.Sensor({
    pin: "A0",
    freq: 300
  });
  sensor2 = new five.Sensor({
    pin: "A1",
    freq: 300
  });

  //scale sensor A0 between 1-2
  sensor1.scale([0, 1000]).on("data", function() {
    if(this.value < 1){
	console.log('A0 Inactive');	
    } else{
       	  console.log('A0 ' + this.value, this.raw);
       };
  });

  //scale sensor A1 between 1-2
  sensor2.scale([0, 1000]).on("data", function() {
    if(this.value < 1){
	console.log('A1 Inactive'); 
    } else{
          console.log('A1 ' + this.value, this.raw);
	};
  });

});
Example #30
0
//BOARD SETUP
var board = new five.Board({
	io: new Particle({
		token: process.env.TOKEN,
		deviceId: process.env.DEVICE_ID
	})
});

//CONTROLLER SETUP
var xbox = new XboxController(process.env.XBOX_SERIAL);

board.on("ready", function() {
	ready = true;
	servo = five.Servo({
		pin: 'A7',
		startAt: 45,
		centered: true,
		range: [0, 90]
	});
});

xbox.on('leftshoulder:press', function(){
	if(ready) {
		servo.min();
	}
});

xbox.on('rightshoulder:press', function(){
	if(ready) {
		servo.max();
	}