const int dataPin = 4; // DS - data serial
const int latchPin = 8; // ST_CP - storage register, latch clock pin
const int clockPin = 7; // SH_CP - shift register clock pin
void updateShiftRegister(unsigned int leds) {
byte left_out = lowByte(leds); // extacts the lower byte, right most byte, from a 16-bit word or unsigned integer
byte right_out = highByte(leds); // extracts the higher byte, left most byte, from a 16-bit word or unsigned integer
digitalWrite(latchPin, LOW);
// LEDs move from left to right
shiftOut(dataPin, clockPin, MSBFIRST, right_out);
shiftOut(dataPin, clockPin, MSBFIRST, left_out);
digitalWrite(latchPin, HIGH);
}
/* ***************************************************
Void Setup
*************************************************** */
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
/* ***************************************************
Void Loop
*************************************************** */
void loop() {
int i=0;
unsigned int leds = 0B0000000000000000;
for(i=0; i<=17; i++){
bitSet(leds, i);
updateShiftRegister(leds);
delay(500);
}
for(i=0; i<=17; i++){
bitClear(leds, i);
updateShiftRegister(leds);
delay(500);
}
}