Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 () {
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],
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],
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)
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 ],
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);
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();
}
});
});
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)
});
board.on("ready", function() {
var buzzer = new five.Piezo(4);
var tetris = songs.load("tetris-theme");
buzzer.play(tetris);
});
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 = () => {