Skip to content

Instantly share code, notes, and snippets.

@nyomo
Created June 18, 2016 12:51
Show Gist options
  • Save nyomo/ad299876ded33b3c7aef8f335a66a9aa to your computer and use it in GitHub Desktop.
Save nyomo/ad299876ded33b3c7aef8f335a66a9aa to your computer and use it in GitHub Desktop.
#include <wiringPi.h>
#include <stdio.h>
#define SCK 28
#define RCK 27
#define SI 29
int leddata(unsigned char pattern1,unsigned char pattern2){
int x;
unsigned char flg;
flg = 0x01;
for(x=0;x<8;x++){
if((pattern2 & flg) == flg) write_bit(0);
else write_bit(1);
pattern2 = pattern2 >> 1;
}
flg = 0x80;
for(x=0;x<8;x++){
if((pattern1 & flg) == flg) write_bit(1);
else write_bit(0);
pattern1 = pattern1 << 1;
}
digitalWrite(SCK,0); digitalWrite(SCK,1); digitalWrite(SCK,0);
}
int write_bit(int i){
digitalWrite(SI,i); digitalWrite(RCK,0); digitalWrite(RCK,1);
return 0;
}
int main(void){
unsigned char x,y;
unsigned char data[8] = {0x3c,0x42,0xa5,0x81,0xa5,0x99,0x42,0x3c};
int i;
if(wiringPiSetup() == -1){
printf("Error\n");
return 1;
}
pinMode(SCK,OUTPUT); pinMode(RCK,OUTPUT); pinMode(SI,OUTPUT);
/*test pattern */
printf("\nstart\n");
for(y=1;y > 0;y=y << 1){
for(x=1;x > 0;x=x << 1){ leddata(x,y); usleep(30000); }
}
for(i=0;i<2;i++){
x=0;
for(y=1;y > 0;y=y << 1){
if(x>8)x=0;leddata(data[x++],y);
usleep(300000);
}
}
/*Nico chan*/
while(1){
for(i=0;i<50000;i++){
x=0;
for(y=1;y > 0;y=y << 1){
if(x>8)x=0;leddata(data[x++],y);
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment