How to use the johnny-five.Sensor function in johnny-five

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 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 webondevices / js-electronics-book / 11-smart-plant-log-chart / smart-plant.js View on Github external
// Setup the thermometer
    var thermometer = new five.Thermometer({
        controller: 'LM35',
        pin: 'A0',
        freq: 1000
    });

    // Setup the light sensor
    var lightSensor = new five.Sensor({
        pin: 'A1',
        freq: 1000
    });

    // Setup the moisture sensor
    var moistureSensor = new five.Sensor({
        pin: 'A2',
        freq: 1000
    });

    // When data is received, update the front end with information from the sensors
    thermometer.on('data', function () {
        sensorData.celsius = this.C;
        server.updateData(sensorData);
    });

    lightSensor.on('data', function () {
        sensorData.light = (this.value / 1024) * 100;
        server.updateData(sensorData);
    });

    moistureSensor.on('data', function () {
github elaval / webduino / lib / webduino-api.js View on Github external
// Get new state from body data Ex: {active:true, freq:500}
    state.active = data.active ? data.active : false;
    state.freq = data.freq ? data.freq : 500;

    // Sensor should be activated
    if (state.active) {

      // There is no Sensor object created or there is one with a different frequency
      if (!this.sensors[id] || (this.sensors[id] && (state.freq !== previousFreq))) {
        // Deactiviate existing sensor with different frequency
        if (this.sensors[id] && (state.freq !== previousFreq)) {
          this.sensors[id].removeAllListeners("data");
        }

        // Create new Sensor
        this.sensors[id] = new five.Sensor({'pin':state.id, 'freq':state.freq});

        // Actions to be taken on data events
        this.sensors[id].on("data", function() {
          var state = self.sensorStates[id];

          // Update state value
          state.value = this.value;

          // Broadcast new value
          self.dataBroadcast("sensors", id, state);
        });
      }

    } 

    // Sensor should be deactivated
github andrew / jquery-uk / nodecopter-hoodie / index.js View on Github external
var onReady = function(){
  console.log("ready to robot");
  var button = new five.Button(7);
  var leftYFlexSensor = new five.Sensor("A0");
  var rightYFlexSensor = new five.Sensor("A1");
  var leftZFlexSensor = new five.Sensor("A2");
  var rightZFlexSensor = new five.Sensor("A3");

  button.on("up", function() {
    toggleFlying();
  });


  leftYFlexSensor.on("read", function(err, value){
    var a= five.Fn.map(value, 100, 500, -90, 90);
    leftY = five.Fn.constrain(a, -80, 80);
    io.sockets.emit('leftY', { angle: leftY, value: value });
    move();
  });
  rightYFlexSensor.on("read", function(err, value){
github mimming / snippets / nodebotyay / photoresistor.js View on Github external
board.on("ready", function() {

  button = new five.Button(8);
  var led = new five.Led(7);
  var photoresistor = new five.Sensor({
    pin: "A2",
    freq: 250
  });


  board.repl.inject({
    button: button,
    led: led,
    photoresistor: photoresistor
  });

  button.on("down", function() {
    console.log("down");
    led.on();
  });
github AnnaGerber / node-ardx / code / CIRC08-code-pot.js View on Github external
board.on("ready", function() {

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

  myLed = new five.Led(9);

  myPotentiometer.on("data", function() {
    var rawValue = this.raw;
    myLed.brightness(Math.floor(rawValue / 4));
  });
});
github sofroniewn / electron-johnny-five-examples / 4-potentiometer / app / index.js View on Github external
board.on('ready', function() {
  document.getElementById('board-status').src = 'icons/ready.png'
  input.className = 'input'
  horn(position-90, '#505050')

  var servo = new five.Servo({pin: 10, startAt: 90, range: [45, 135]})
  var sensor = new five.Sensor({
      pin: 'A0', 
      freq: 25, 
  });
    
  sensor.scale(45, 135).on('data', function (){
    position = Math.round(sensor.value)
    input.value = String(position) + String.fromCharCode(176)

    servo.to(position)
    draw(position-90, '#505050')
  })
})
github webondevices / js-electronics-book / 12-smart-plant-speak / smart-plant.js View on Github external
arduino.on('ready', function () {
    
    var thermometer = new five.Thermometer({
        controller: 'LM35',
        pin: 'A0',
        freq: 1000
    });

    var lightSensor = new five.Sensor({
        pin: 'A1',
        freq: 1000
    });

    var moistureSensor = new five.Sensor({
        pin: 'A2',
        freq: 1000
    });

    thermometer.on('data', function () {
        sensorData.celsius = this.C;
        server.updateData(sensorData);
        speak.interpret(sensorData);
    });

    lightSensor.on('data', function () {

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