#define ds 2
#define clk 4
#define latch 3
void setup() {
pinMode(ds, OUTPUT);
pinMode(clk, OUTPUT);
pinMode(latch, OUTPUT);
}
bool a=1;
int mode = 0;
int i;bool b;
void loop() {
if(mode==0)for( i=0;i<=15;i++){setLed(i,a);delay(100);}
if(mode==1)for( i=0;i<=7;i++){setLed(i,a);setLed(15-i,a);delay(100);}
if(mode==2)for( i=7;i>=0;i--){setLed(i,a);setLed(15-i,a);delay(100);}
a =!a;
mode = mode>3?0:mode+1;
setAll(0);
a=1;
}
void shiftOut(char val)
{
for (char i = 0; i <8; i++) {
digitalWrite(ds, !!(val & (1 << (7 - i))));
digitalWrite(clk, HIGH);
digitalWrite(clk, LOW);
}
}
char byte1, byte2;
#define setbit(x,y) x|= (1<<y)
#define clearbit(x,y) x&= ~(1<<y)
void setLed(char index, bool level) {
if (index < 8)
//byte1=write(byte1 ,index,level);
if(level)setbit(byte1,index);
else clearbit(byte1,index);
else
//byte2=write(byte2,index, level);
if(level)setbit(byte2,index-8);
else clearbit(byte2,index-8);
digitalWrite(latch,0);
shiftOut(byte1);
shiftOut(byte2);
digitalWrite(latch,1);
}
void setAll(bool l){
byte1 = l?255:0;
byte2=byte1;
digitalWrite(latch,0);
shiftOut(byte1);
shiftOut(byte2);
digitalWrite(latch,1);
}