const int tDelay = 100;
const int dataPin = 8;
const int latchPin = 9;
const int clockPin = 10;
bool DirectionState = 0;
void updateShiftRegister(unsigned int leds, bool isMSBFIRST = true){
byte lowLED = lowByte(leds);
byte highLED = highByte(leds);
digitalWrite(latchPin, LOW);
if (isMSBFIRST == false) {
shiftOut(dataPin, clockPin, LSBFIRST, lowLED);
shiftOut(dataPin, clockPin, LSBFIRST, highLED);
} else {
shiftOut(dataPin, clockPin, MSBFIRST, highLED);
shiftOut(dataPin, clockPin, MSBFIRST, lowLED);
}
digitalWrite(latchPin, HIGH);
}
void setup(){
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop(){
unsigned int leds = 0B000000000000000000000000;
updateShiftRegister(leds);
delay(tDelay);
for (int i = 0; i < 24; i++){
leds = 0B000000000000000000000000;
bitSet(leds, i);
updateShiftRegister(leds, DirectionState);
delay(tDelay);
}
DirectionState = !DirectionState;
}