-
Notifications
You must be signed in to change notification settings - Fork 2
/
color.cpp
32 lines (23 loc) · 882 Bytes
/
color.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "ws281x.hpp"
#include <stdio.h>
using namespace ws281x;
int main(int argc, char* argv[])
{
// set one color passed on the command-line to all LEDs
unsigned char red,green,blue;
if(argc != 2 || sscanf(argv[1], "%hhx:%hhx:%hhx", &red, &green, &blue) != 3)
{
fprintf(stderr, "ERROR: usage is: '%s' <RR>:<GG>:<BB>\nwhere RR, GG and BB are hexadecimal numbers\n", argv[0]);
return 1;
}
// attach an instance of the SPI-driver to the first SPI device on the first bus (0.0)
TSPIDriver spi_dev_1("/dev/spidev0.0", HZ_SPI_NEOPIXEL);
const unsigned n_pixels = 60;
TWS2812B arr_pixels[n_pixels];
for(unsigned i = 0; i < n_pixels; i++)
arr_pixels[i].RGB(red, green, blue);
// now we send the data to the LEDs:
spi_dev_1.SendData(arr_pixels, sizeof(arr_pixels));
// c++ destructors will take care of proper shutdown and release of resources...
return 0;
}