Project tutorial
Linino Christmas with Lifx

Linino Christmas with Lifx

Make Christmas lights that vary color with the music!

  • 1,161 views
  • 0 comments
  • 1 respect

Components and supplies

About this project

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 smart wifi lamp Lifx. Each note will correspond to a different color of the lamp.

What we need:

Warning: embedding parts within the project story has been deprecated. To edit, remove or add more parts, go to the "Hardware" tab. To remove this list from the story, click on it to trigger the context menu, then click the trash can button (this won't delete it from the "Hardware" tab).
Ard yun
Arduino Yun
Lifx
Buzzer


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

package.json:

Code

Warning: Embedding code files within the project story has been deprecated. To edit this file or add more files, go to the "Software" tab. To remove this file from the story, click on it to trigger the context menu, then click the trash can button (this won't delete it from the "Software" tab).

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

The code of the script:

Code

Warning: Embedding code files within the project story has been deprecated. To edit this file or add more files, go to the "Software" tab. To remove this file from the story, click on it to trigger the context menu, then click the trash can button (this won't delete it from the "Software" tab).

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

Download the file tone.json

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

Code

code.txtJSON
{
  "name": "XmasLifx",
  "version": "0.0.1",
  "description": "Ideino project",
  "author": {
    "name": "Ideino Team"
  },
    "dependencies": {
        "lifx": "*"
    }
}
code.txtJavaScript
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);

});

Comments

Similar projects you might like

Control a Parrot AR Drone with Linino

Project tutorial by Giando

  • 6,391 views
  • 2 comments
  • 18 respects

Ask Wolfram and Linino Answers!

Project tutorial by Giando

  • 679 views
  • 1 comment
  • 1 respect

Home-made Nest Protect with Linino

Project tutorial by Giando

  • 1,227 views
  • 0 comments
  • 3 respects

DIY Christmas Tree and Christmas Decor Using Arduino

Project tutorial by STEMpedia

  • 704 views
  • 0 comments
  • 4 respects

Alexa-Powered Christmas Tree

Project tutorial by Kay Lerch

  • 13,607 views
  • 7 comments
  • 27 respects

Arduino Christmas Cheer!

Project tutorial by Dante Roumega

  • 1,949 views
  • 0 comments
  • 5 respects
Add projectSign up / Login