How to use the johnny-five.Button 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 webondevices / js-electronics-book / 04-push-button / button.js View on Github external
arduino.on('ready', function () {
    
    // Access the push button on pin D2
    var button = new five.Button(2);

    // Access the LED on pin D6
    var led = new five.Led(6);

    // Event listeners with callback functions
    // Will capture button down event
    button.on('down', function () {
        led.on();
        console.log('button is pressed');
    });

    // Will capture button held down event
    button.on('hold', function () {
        led.blink(100);
        console.log('button is held down for over half a second');
    });
github charliegerard / gestures-ml-js / arduino-mkr1000 / examples / game / predict.js View on Github external
board.on("ready", function() {
        console.log("Board ready!");
        const button = new five.Button("A0");

        const imu = new five.IMU({
            pins: [11,12], // connect SDA to 11 and SCL to 12
            controller: "MPU6050"
        });

        imu.on("data", function() {
            let dataAvailable = this.accelerometer.x;

            if(dataAvailable && !started){
                console.log('imu ready')
            }
            
            button.on("hold", () => {
                predictionDone = false;
                let data = {xAcc: this.accelerometer.x,
github sayanee / talks / web-sensors / code / 5-button.js View on Github external
board.on('ready', function() {
  button = new five.Button(2) // digital pin 2

  board.repl.inject({
    button: button
  })

  button.on('down', function() {
    console.log('down')
  })

  button.on('hold', function() {
    console.log('hold')
  })

  button.on('up', function() {
    console.log('up')
  })
github tableflip / nodebot-workshop / exercises / fire_alarm / solution / solution.js View on Github external
board.on('ready', function () {
  var piezo = new five.Piezo(9)
  var led = new five.Led(13)
  var btn = new five.Button(5)
  var thermo = new five.Sensor('A0')

  var threshold = 50
  var isOnFire = false
  var isReset = false

  var sirenInterval = null

  // Sound the alarm
  function panic () {
    if (isOnFire) return
    isOnFire = true

    led.strobe(1000)
    piezo.tone(five.Piezo.Notes.c4, 750)
    sirenInterval = setInterval(function () {
github mimming / snippets / nodebotyay / quickstart.js View on Github external
board.on("ready", function() {

  button = new five.Button(8);
  var led = new five.Led(7);

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

  button.on("down", function() {
    console.log("down");
    led.on();
  });

  button.on("up", function() {
    console.log("up");
		led.off();
  });
github urish / angular-iot / src / components / button.component.ts View on Github external
ngOnInit() {
    this._button = new five.Button({
      pin: this.pin,
      isPullup: this.pullup
    });

    this._button.on('down', () => {
      this.zone.run(() => {
        this.click.emit({
          pin: this.pin
        });
      });
    });
  }
}
github stevekinney / nodebots-workshop / playground.js View on Github external
board.on('ready', () => {
  const led = new five.Led('a0');

  const button = new five.Button({
    pin: 'a2',
    isPullup: true,
  });

  button.on('press', () => led.on());
  button.on('release', () => led.off());
});
github rwaldron / johnny-five / eg / arduino-starter-kit / motorized-pinwheel.js View on Github external
board.on("ready", function() {
  var gate = new five.Pin(9);
  var button = new five.Button(2);
  button.on("press", function() {
    gate.write(1);
  });
  button.on("release", function() {
    gate.write(0);
  });
});
github vnovick / react-iot / src / components / Button.js View on Github external
componentWillMount(){
    const { pin, invert, isPullup } = this.props;
    this.button = new five.Button({
      pin,
      isPullup,
      invert
    });
    this.setButtonEvents(this.props);
  }
github rwaldron / johnny-five / eg / arduino-starter-kit / spaceship-interface.js View on Github external
board.on("ready", function() {

  var leds = five.Leds([3,4,5]);
  var btn = five.Button(2);

  btn.on("press", function() {
    leds[0].off();
    leds[1].on().blink(500);
    leds[2].off().blink(500);
  });

  btn.on("release", function() {
    leds[0].on();
    leds[1].off().stop();
    leds[2].off().stop();
  });

});

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