I have some trouble writing data to APA102 LED strip.
In my example I just do the same as the documentation said.
4 bytes of 0x00 as a start frame.
For each LED, a brightness byte (0xE0 + value), a blue value byte, a green value byte, and a red value byte.
(N/2)/8 bytes of 0xFF as an end frame, where N is the number of LEDs.
result is following source:
SPI2.setup({mosi:B15, sck:B13, baud:4000000});
var NumLEDs = 150;
var leds = new Uint8Array(NumLEDs*4);
function draw() {
var millis = getTime();
var r = Math.random()*255;
var g = Math.random()*255;
var b = Math.random()*255;
for (var pixel = 0; pixel < leds.length; pixel+=4)
{
leds[pixel+0] = 0xE0 | 5;
leds[pixel+1] = b;
leds[pixel+2] = g;
leds[pixel+3] = r;
}
write_leds(leds, NumLEDs);
}
function write_leds(leds, numLeds) {
var halfLed = numLed/16 + 1; // compute end frame length
var maxIndex = numLed * 4; // maximum leds row index;
var index;
SPI2.write(0x00);
SPI2.write(0x00);
SPI2.write(0x00);
SPI2.write(0x00);
// LED Frame
for (index = 0; index < maxIndex; index+=4) {
SPI2.write(leds[index+0]); // global brigthness
SPI2.write(leds[index+1]); // B
SPI2.write(leds[index+2]); // G
SPI2.write(leds[index+3]); // R
} // for all leds
// End Frame
for (index = 0; index < halfLed; index++) {
SPI2.write(0xFF);
} // for end frame
} // write_leds()
function onInit() {
setInterval(draw, 50);
}
onInit();
But it seems that the data I send is not the data I see.
Also if I change the pixel data to show only red pixels; there is always a kind of random colors to see :/
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I have some trouble writing data to APA102 LED strip.
In my example I just do the same as the documentation said.
result is following source:
But it seems that the data I send is not the data I see.
Also if I change the pixel data to show only red pixels; there is always a kind of random colors to see :/
Hope someone can help me here to fix the problem.