#define ds 2
#define clk 3
#define latch 4
void setup() {
pinMode(ds, OUTPUT);
pinMode(clk, OUTPUT);
pinMode(latch, OUTPUT);
}
void loop() {
setLed(0,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, byte3;
#define setbit(x,y) x|= (1<<y)
#define clearbit(x,y) x&= ~(1<<y)
void setLed(char index, bool level) {
if (index <= 8)
write(byte1 ,index,level);
if (index <= 16)
write(byte2,index, level);
if (index <= 32)
write(byte3,index, level);
digitalWrite(latch,0);
shiftOut(byte3);
shiftOut(byte2);
shiftOut(byte1);
digitalWrite(latch,1);
}
void write(char b,char i, bool l) {
if (l)setbit(b, i);
if (!l)clearbit(b, i);
}