Linino Christmas with Lifx

An example dedicated to the Christmas period, which exploits the potential of our system with Node.js.
The script will perform a classic Christmas tune that will interact with the lamp smart wifi Lifx. For each note will correspond to a different color of the lamp.

What we need:

Linino One or Arduino Yun
image00

Lifx
lifx-product-photos-14

Buzzer
buzzer

We create a new project in the workspace Ideino. In the file package.json insert addiction module lifx.

package.json:

{
  "name": "XmasLifx",
  "version": "0.0.1",
  "description": "Ideino project",
  "author": {
    "name": "Ideino Team"
  },
    "dependencies": {
        "lifx": "*"
    }
}

The code of the script:

var linino = require('ideino-linino-lib'),
    board = new linino.Board(),
    tone = require('tone.json'),
    buz = board.pin.pwm.P5;
    var del = 0;
 
var lifx = require('lifx');
var lx = lifx.init();
 
var jbells = [
        "NOTE_E5", "NOTE_E5", "NOTE_E5", "NOTE_E5", "NOTE_E5", "NOTE_E5", "NOTE_E5", "NOTE_G5", "NOTE_C5", "NOTE_D5", "NOTE_E5",
        "NOTE_F5", "NOTE_F5", "NOTE_F5", "NOTE_F5", "NOTE_F5", "NOTE_E5", "NOTE_E5", "NOTE_E5", "NOTE_E5", "NOTE_D5", "NOTE_D5", "NOTE_E5", "NOTE_D5", "NOTE_G5",
        "NOTE_E5", "NOTE_E5", "NOTE_E5", "NOTE_E5", "NOTE_E5", "NOTE_E5", "NOTE_E5", "NOTE_G5", "NOTE_C5", "NOTE_D5", "NOTE_E5",
        "NOTE_F5", "NOTE_F5", "NOTE_F5", "NOTE_F5", "NOTE_F5", "NOTE_E5", "NOTE_E5", "NOTE_E5", "NOTE_G5", "NOTE_G5", "NOTE_F5", "NOTE_D5", "NOTE_C5", "0", "0"
];
var jbellstimes = [
    200, 200, 400, 200, 200, 400, 200, 200, 200, 200, 800,
    200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 400, 400,
    200, 200, 400, 200, 200, 400, 200, 200, 200, 200, 800,
    200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 800
];
 
lx.lightsOn();
 
function play(melody, times) {
    board.noTone(buz);
    for (thisNote = 0; thisNote < melody.length; thisNote++) {
        sendsound(tone.tone[melody[thisNote]], del);
        del = times[thisNote] + del;
    }
 
}
 
function sendsound(sound, time) {
    setTimeout(function() {
        board.tone(buz, sound);
        lx.lightsColour((sound * 16384) & 0xFFFF, 32767, 65535, 0, 0);
    }, time);
}
 
 
board.connect(function() {
    board.pinMode(buz, board.MODES.PWM);
 
    play(jbells, jbellstimes);
 
});

We connect the buzzer to Pin PWM 5.
Require file tone.json, because we use to map each note to a corresponding frequency. Download the file tone.json

We send running the file and let’s enjoy this new Christmas.

GIF_20141206_001642