Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
68 lines (41 sloc) 971 Bytes
#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);
}