I'm trying to use a blinkm led from node.js using the node i2c-bus package.
The problem I'm having is that the blinkm expects the color of the led to be set using the format
{'n',R,G,B}
, which will actually be {'n',0xff,0xee,0x30}
.
Using the i2c-bus, I am passing the above format as a buffer, so in node, I have written this function to take an rgb object and return it as a buffer in the correct format
function formatBuffer(val) {
return new Buffer({'n', val.r , val.g, val.b});
}
and then call it with
formatBuffer({r:0xff, g:0xee, b:0x30});
unfortunately, this returns an error unexpected token ,
which I'm assuming is the first comma after then 'n'.
I've tried wrapping the value in a string, which doesn't through the error, but also doesn't seem to work.
Any suggestions on how I can get around this and pass the right format through javascript to the blinkm led?
Because the { 'n', val.r , val.g, val.b }
is not object format (lack of key). Change to array [0x6e, val.r , val.g, val.b]
or { 'key1': 0x6e, 'key2': val.r , 'key3': val.g, 'key4': val.b }