forked from armageddon421/blinkenpi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c~
67 lines (41 loc) · 971 Bytes
/
main.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
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/spi/spidev.h>
#include <string.h>
#include <wiringPiSPI.h>
#define SPI_CHANNEL 0
#define LED_NUM 23
//output buffer
unsigned char output[LED_NUM*3];
//prototypes
void update();
void led_set(int id, char r, char g, char b);
int main(void){
//init SPI
if (wiringPiSPISetup (SPI_CHANNEL, 100000) < 0)
printf("SPI Setup error\n");
int i;
for(i=0;i<LED_NUM;i++){
led_set(i,255,255,255);
}
for (i=0; i<10000;){
update();
}
}
void led_set(int id, char r, char g, char b){
output[id*3 + 0] = r | 0x80;
output[id*3 + 1] = g | 0x80;
output[id*3 + 2] = b | 0x80;
}
void update(){
unsigned char temp[LED_NUM*3];
unsigned char latch[3] = {0,0,0};
memcpy(temp,output, LED_NUM*3);
wiringPiSPIDataRW (SPI_CHANNEL, temp, LED_NUM*3) ;
wiringPiSPIDataRW (SPI_CHANNEL, latch, 3) ;
usleep(1000);
}