How to use the johnny-five.Piezo 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 / 06-motion-alarm / alarm.js View on Github external
arduino.on('ready', function () {

    // Setup the components
    var led = new five.Led(6);
    var piezo = new five.Piezo(10);
    var motion = new five.Motion(4);

    var alarmTone = [['C4', 1], ['C3', 1], ['C4', 1], ['C3', 1]];

    // When motion is detected, blink the LED and play the alarm tone
    motion.on('motionstart', function () {
        led.blink(250);

        piezo.play({
            song: alarmTone,
            tempo: 50
        });
    });
  
    // Stop the LED flashing when the motion stops
    motion.on('motionend', function () {
github Makeblock-official / mbot_nodebots / examples / piezo.js View on Github external
board.on("ready", function() {
  // Creates a piezo object and defines the pin to be used for the signal
  var piezo = new five.Piezo(8);

  // 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],
github julianduque / nodebots-workshop / content / music_player / music_player.js View on Github external
board.on('ready', function() {
  piezo = new five.Piezo(6);

  // 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],
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)
github sayanee / talks / web-sensors / code / 4-buzzer.js View on Github external
board.on('ready', function() {
  var piezo = new five.Piezo(3) // Digital PWM pin 3

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

  piezo.play({
    tempo: 120,
    song: [
      [ 'c4', 1 ],
      [ null, 1 ],
      [ 'd4', 1 ],
      [ null, 1 ],
      [ 'e4', 1 ],
      [ null, 1 ],
      [ 'f4', 1 ],
      [ null, 1 ],
github willmendesneto / nodebots-workshop / src / memory-game.js View on Github external
board.on('ready', function() {

  leds = new five.Leds([12, 3]);
  var buttons = new five.Buttons([13, 2]);

  piezo = new five.Piezo(11);

  buttons.on('press', function(button) {
    if (buttonsSequence.length) {
      var index = buttons.indexOf(button);
      leds[index].on();
      console.log('Pressed: button', button.pin, 'led', leds[index].pin);
      piezo.play({ song: piezoSongs[index] });
    }
  });

  buttons.on('release', function(button) {
    if (buttonsSequence.length) {
      var index = buttons.indexOf(button);

      console.log('Released: button', button.pin, 'led', leds[index].pin);
github rwaldron / johnny-five / eg / arduino-starter-kit / keyboard.js View on Github external
board.on("ready", function() {
  var sensor = new five.Sensor({
    pin: "A0",
    freq: 100,
    threshold: 8
  });
  var piezo = new five.Piezo(8);
  sensor.on("change", function() {
    console.log(this.value);
    if (five.Fn.inRange(this.value, 1020, 1023)) {
      piezo.frequency(five.Piezo.Notes["c4"], 50);
    } else if (five.Fn.inRange(this.value, 990, 1010)) {
      piezo.frequency(five.Piezo.Notes["d4"], 50);
    } else if (five.Fn.inRange(this.value, 500, 520)) {
      piezo.frequency(five.Piezo.Notes["e4"], 50);
    } else if (five.Fn.inRange(this.value, 20, 40)) {
      piezo.frequency(five.Piezo.Notes["f4"], 50);
    } else {
      piezo.noTone();
    }
  });
});
github tableflip / nodebot-workshop / exercises / ping_bell / solution / solution.js View on Github external
board.on('ready', function () {
  var piezo = new five.Piezo(8)
  var server = dgram.createSocket('udp4')

  server.on('message', function () {
    piezo.play({
      song: 'C D F D A',
      beats: 1 / 4,
      tempo: 100
    });
  });

  server.bind(1337)
});
github w4ilun / edison-guides / recipies / Johnny-Five Examples / buzzer.js View on Github external
board.on("ready", function() {
  var buzzer = new five.Piezo(4);
  var tetris = songs.load("tetris-theme");
  buzzer.play(tetris);
});
github nodebotsau / simplebot / examples / snes-controller.js View on Github external
board.on("ready", () => {

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

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

    let piezo = new five.Piezo(10);

    controller.up = () => {
        motor_l.forward(250);
        motor_r.forward(250);
    };
    controller.down = () => {
        motor_l.reverse(250);
        motor_r.reverse(250);
    };
    controller.left = () => {
        motor_l.forward(250);
    };
    controller.right = () => {
        motor_r.forward(250);
    };
    controller.l = () => {

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