Skip to content

Instantly share code, notes, and snippets.

@smukkejohan
Forked from DirkWillem/wiringpi_apa102.cpp
Last active October 31, 2018 13:37
Show Gist options
  • Save smukkejohan/917793c8cc40f3aaf2a5d938777d04c0 to your computer and use it in GitHub Desktop.
Save smukkejohan/917793c8cc40f3aaf2a5d938777d04c0 to your computer and use it in GitHub Desktop.
#include <wiringPi.h>
#include <wiringPiSPI.h>
#include <iostream>
#include <stdint.h>
int main() {
wiringPiSetup();
if(wiringPiSPISetup(0, 6000000) < 0) {
std::cerr << "wiringPiSPISetup failed" << std::endl;
}
uint8_t buf[1];
for(int i = 0; i < 4; i++) {
buf[0] = 0x00;
wiringPiSPIDataRW(0, buf, 1);
}
uint8_t r, g, b, brightness;
r = 0xFF;
g = 0x00;
b = 0x00;
brightness = 15;
uint8_t led_frame[4];
for(int i = 0; i < 8; i++) {
led_frame[0] = 0b11100000 | (0b00011111 & brightness);
led_frame[1] = b;
led_frame[2] = g;
led_frame[3] = r;
wiringPiSPIDataRW(0, led_frame, 4);
}
for(int i = 0; i < 4; i++) {
buf[0] = 0xFF;
wiringPiSPIDataRW(0, buf, 1);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment