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.
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.
Following modifications are necessary:
- Remove the micro controller
1
from the circuit board. - Solder 4 wires to
2
,R
,G
andB
. - Connect
2
to aGND
pin on the Raspberry Pi. - Connect
R
,G
andB
to GPIO pins (preferablyGPIO4
,GPIO17
andGPIO18
) on the Raspberry Pi.
Install the pi-blaster daemon (instructions) and Node.js with npm.
Finally install redoid
using npm:
npm install redoid
var Redoid = require('redoid');
var redoid = Redoid({
color: '#ffffff'
});
redoid.transition('#249db3', 250);
redoid.transition('#ffffff', 4000);
var Redoid = require('redoid');
var redoid = Redoid({
color: '#300000',
loopTransition: true
});
redoid.transition('#ff0000', 1500);
redoid.transition('#300000', 1500);
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(i ++ % 2 === 0 ? '#ff0000' : '#ffffff', 2000, easing);
}
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 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 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;
}
Queue transition from the last queued color (obtained by getLastQueuedColor
) to the color provided.
redoid.transition(color, [duration], [easing]);
Queue color change to color provided.
redoid.change(color);
Queue turning off the lights.
redoid.turnOff([duration]);
Delay next queue entry by given duration.
redoid.delay(duration);
Trigger callback when transition reaches this transition step.
redoid.trigger(callback);
Interrupt the current transition and clear the queue. When firing this method, no callbacks set by trigger
get called.
redoid.stop();
Return the current color. (e.g. [255, 0, 0]
)
var color = redoid.getColor();
Return hex value of current color. (e.g. #ff0000
)
var color = redoid.getColorHexValue();
Return the last queued color. If loopTransition
is set to true
, this value changes during transiton.
var color = redoid.getLastQueuedColor();
Return hex value of last queued color.
var color = redoid.getLastQueuedColorHexValue();
Check if color is valid.
var colorValid = redoid.isColorValid(color)
Check if colors are equal.
var colorEqual = redoid.isColorEqual(a, b)
Returns true
when currently inside transition.
var transitioning = redoid.isTransitioning();
Set the loopTransition
option.
redoid.setLoopTransition(loopTransition);
Set the idleColor
option.
redoid.setIdleColor(idleColor);