redoid

0.1.4 • Public • Published

redoid

npm npm MIT license

A Node.js package that provides an API to control your IKEA Dioder LED light strip from your Raspberry Pi. Read redoid the other way round to understand where its name came from.

Installation

Connect Dioder to Raspberry Pi

Please notice that you need to apply physical changes to the circuit board of your Dioder control unit in order to connect it to the Raspberry Pi. After that you will no longer be able to use the buttons on the control unit to change the behavior of the LEDs.

Open the IKEA Dioder control unit carefully with a screwdriver. We are aware of following two versions of the circuit board inside it. Both are compatible with this modification.

Dioder control unit circuit board

Following modifications are necessary:

  • Remove the micro controller 1 from the circuit board.
  • Solder 4 wires to 2, R, G and B.
  • Connect 2 to a GND pin on the Raspberry Pi.
  • Connect R, G and B to GPIO pins (preferably GPIO4, GPIO17 and GPIO18) on the Raspberry Pi.

Install Dependencies

Install the pi-blaster daemon (instructions) and Node.js with npm.

Finally install redoid using npm:

npm install redoid

Examples

Simple Alert

var Redoid = require('redoid');
var redoid = Redoid({
    color: '#ffffff'
});
 
redoid.transition('#249db3', 250);
redoid.transition('#ffffff', 4000);

Red Alert

var Redoid = require('redoid');
var redoid = Redoid({
    color: '#300000',
    loopTransition: true
});
 
redoid.transition('#ff0000', 1500);
redoid.transition('#300000', 1500);

Easing

var Redoid = require('redoid');
var redoid = Redoid({
    color: '#ffffff'
});
 
var i = 0;
 
for (var easing in Redoid.easingFunctions)
{
    // trigger method logging the used easing function
    redoid.trigger(function() {
        console.log('' + this);
    }.bind(easing));
 
    redoid.delay(1000);
    redoid.transition(++ % 2 === 0 ? '#ff0000' : '#ffffff', 2000, easing);
}

Usage

Instance

You can create one or more Redoid instances by calling its constructor. The constructor takes one optional associative array with following keys to configure the instance:

  • color – Initial color to apply when an instance gets created.
  • colorComponentPins – Array holding 3 integer values of the RGB GPIO pins dioder is connected to.
  • applyColorCallback – Custom function that replaces the default mechanism for applying colors. This feature is disabled if set to null.
  • loopInterval – Duration between transitioning ticks.
  • defaultEasing – Default easing
  • idleTimeout – Delay between the queue being idle and the idle event getting triggered.
  • idleCallback – Function that gets called when the idle event gets triggered.
  • idleColor – Idle color to transition to when the idle event gets triggered. This feature is disabled if set to null.
  • idleColorTransitionDuration – Idle color transition duration
  • loopTransition – If set to true completed transition steps will be added to the end of the queue resulting in a never-ending transition loop.

The following instance gets configured with the default values:

var Redoid = require('redoid');
 
var redoid = Redoid({
    color: '#ffffff',
    colorComponentPins: [4, 17, 18],
    applyColorCallback: null,
    loopInterval: 25,
    defaultEasing: 'easeInOutQuad',
    idleTimeout: 0,
    idleCallback: null,
    idleColor: null,
    idleColorTransitionDuration: 4000,
    loopTransition: false
});

Color

Color values are expected to be rgb hexadecimal strings or arrays having 3 integer values representing the rgb color components.

// hexadecimal
var color = '#ff0000';
 
// shorthand hexadecimal
var color = '#f00';
 
// color components
var color = [255, 0, 0];

Easing

Easing values are expected to be a function or one of the following keys: linear, easeInQuad, easeOutQuad, easeInOutQuad, easeInCubic, easeOutCubic, easeInOutCubic, easeInQuart, easeOutQuart, easeInOutQuart, easeInQuint, easeOutQuint, easeInOutQuint.

// known easing function by name
var easing = 'easeInOutQuad';
 
// easing function
var easing = function(t) {
    return t<.5 ? 2*t*t : -1+(4-2*t)*t;
}

API

transition

Queue transition from the last queued color (obtained by getLastQueuedColor) to the color provided.

redoid.transition(color, [duration], [easing]);

change

Queue color change to color provided.

redoid.change(color);

turnOff

Queue turning off the lights.

redoid.turnOff([duration]);

delay

Delay next queue entry by given duration.

redoid.delay(duration);

trigger

Trigger callback when transition reaches this transition step.

redoid.trigger(callback);

stop

Interrupt the current transition and clear the queue. When firing this method, no callbacks set by trigger get called.

redoid.stop();

getColor

Return the current color. (e.g. [255, 0, 0])

var color = redoid.getColor();

getColorHexValue

Return hex value of current color. (e.g. #ff0000)

var color = redoid.getColorHexValue();

getLastQueuedColor

Return the last queued color. If loopTransition is set to true, this value changes during transiton.

var color = redoid.getLastQueuedColor();

getLastQueuedColorHexValue

Return hex value of last queued color.

var color = redoid.getLastQueuedColorHexValue();

isColorValid

Check if color is valid.

var colorValid = redoid.isColorValid(color)

isColorEqual

Check if colors are equal.

var colorEqual = redoid.isColorEqual(a, b)

isTransitioning

Returns true when currently inside transition.

var transitioning = redoid.isTransitioning();

setLoopTransition

Set the loopTransition option.

redoid.setLoopTransition(loopTransition);

setIdleColor

Set the idleColor option.

redoid.setIdleColor(idleColor);

Package Sidebar

Install

npm i redoid

Weekly Downloads

0

Version

0.1.4

License

MIT

Unpacked Size

22.2 kB

Total Files

6

Last publish

Collaborators

  • ffraenz