Skip to content
Newer
Older
100644 68 lines (41 sloc) 971 Bytes
3627eb0 @armageddon421 added everything
authored Dec 17, 2012
1
2
3 #include <stdio.h>
4 #include <stdint.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <fcntl.h>
8 #include <sys/ioctl.h>
9 #include <linux/spi/spidev.h>
10 #include <string.h>
11
12 #include <wiringPiSPI.h>
13
14
15 #define SPI_CHANNEL 0
16
17 #define LED_NUM 23
18
19 //output buffer
20 unsigned char output[LED_NUM*3];
21
22
23 //prototypes
24 void update();
25 void led_set(int id, char r, char g, char b);
26
27
28 int main(void){
29
30
31 //init SPI
32 if (wiringPiSPISetup (SPI_CHANNEL, 100000) < 0)
33 printf("SPI Setup error\n");
34
35 int i;
36 for(i=0;i<LED_NUM;i++){
37 led_set(i,255,255,255);
38 }
39
40 for (i=0; i<10000;){
41 update();
42
43 }
44
45 }
46
47
48 void led_set(int id, char r, char g, char b){
49
50 output[id*3 + 0] = r | 0x80;
51 output[id*3 + 1] = g | 0x80;
52 output[id*3 + 2] = b | 0x80;
53 }
54
55
56 void update(){
57
58
59 unsigned char temp[LED_NUM*3];
60 unsigned char latch[3] = {0,0,0};
61
62 memcpy(temp,output, LED_NUM*3);
63
64 wiringPiSPIDataRW (SPI_CHANNEL, temp, LED_NUM*3) ;
65 wiringPiSPIDataRW (SPI_CHANNEL, latch, 3) ;
66 usleep(1000);
67 }
Something went wrong with that request. Please try again.