I'm working a little project using a neopixel like matrix board. The board in question is here. Now this is my first adventure into addressable led boards. And I was extremely frustrated to learn that the board came with zero documentation nor was there really anything about it on the internet. I did eventually find some docs on the LEDs on the board.
They are the WS2812b, The docs are here. So I've written some code based on my perception of how it works. The docs arent really the best. So I'm sure i'm misunderstanding it.
Heres the code for it.
using namespace std;
#define DATA 23
void send1()
{
//T1H
digitalWrite(DATA, HIGH);
usleep(0.85);
//T1L
digitalWrite(DATA, LOW);
usleep(0.4);
}
void send0()
{
//T0H
digitalWrite(DATA, HIGH);
usleep(0.4);
//T1L
digitalWrite(DATA, LOW);
usleep(0.85);
}
void sendReset()
{
//Treset
digitalWrite(DATA, LOW);
usleep(55);
}
int main(void)
{
wiringPiSetupSys();
while (true)
{
//256 pixels total
for (int i = 0; i < 256; i++) {
//3 bytes GRB
for (int a = 0; a < 3; a++) {
//G set to 0
for (int g = 0; g < 8; g++) {
send0();
}
//R set to 255
for (int r = 0; r < 8; r++) {
send1();
}
//B set to 0
for (int b = 0; b < 8; b++) {
send0();
}
}
//reset after bytes sent
sendReset();
}
}
return 0;
}
Heres the result
As you can see it doesn't work at all!
Using that code I ran a scope on my gpio pin and this is what that looks like.
I've been working on this for a few hours and the most I've been able to do is turn on all the LEDs to white. And I did that with this code
while (true) {
digitalWrite(DATA, HIGH);
digitalWrite(DATA, LOW);
}
This does reliably turn everything white at least.