-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpattern_test_01.c
87 lines (76 loc) · 2.21 KB
/
pattern_test_01.c
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* simple_example.c
*
* Copyright 2012 Christopher De Vries
* This program is distributed under the Artistic License 2.0, a copy of which
* is included in the file LICENSE.txt
*/
#include "lpd8806led.h"
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
int fd; /* SPI device file descriptor */
const int leds = 500; /* 50 LEDs in the strand */
lpd8806_buffer buf; /* Memory buffer for pixel values */
int count; /* Count of iterations (up to 3) */
int i; /* Counting Integer */
set_gamma(2.5,2.5,2.5);
/* Open SPI device */
fd = open("/dev/spidev0.0",O_WRONLY);
if(fd<0) {
/* Open failed */
fprintf(stderr, "Error: SPI device open failed.\n");
exit(1);
}
/* Initialize SPI bus for lpd8806 pixels */
if(spi_init(fd)<0) {
/* Initialization failed */
fprintf(stderr, "Unable to initialize SPI bus.\n");
exit(1);
}
/* Allocate memory for the pixel buffer and initialize it */
if(lpd8806_init(&buf,leds)<0) {
/* Memory allocation failed */
fprintf(stderr, "Insufficient memory for pixel buffer.\n");
exit(1);
}
/* Loop Forever */
while(1) {
/* Do three iterations */
for(count=0;count<3;count++) {
/* Write color for every pixel */
for(i=0;i<leds;i++) {
if((i+count)%3==0) {
/* Red pixel */
write_gamma_color(&buf.pixels[i],255,0,0);
}
else if((i+count)%3==1) {
/* Green pixel */
write_gamma_color(&buf.pixels[i],0,255,0);
}
else {
/* Blue pixel */
write_gamma_color(&buf.pixels[i],0,0,255);
}
}
/* Send the data to the lpd8806 lighting strand */
if(send_buffer(fd,&buf)<0) {
fprintf(stderr, "Error sending data.\n");
exit(1);
}
/* Sleep for 1 second */
usleep(1000000/60.0f);
}
}
for(i=0;i<leds;i++) {
write_gamma_color(&buf.pixels[i],0x00,0x00,0x00);
}
send_buffer(fd,&buf);
/* Although the program never gets to this point, below is how to clean up */
/* Free the pixel buffer */
lpd8806_free(&buf);
/* Close the SPI device */
close(fd);
return 0;
}