#define DATA_PIN 8 // Pin connected to DS of 74HC595
#define LATCH_PIN 9 // Pin connected to STCP of 74HC595
#define CLOCK_PIN 10 // Pin connected to SHCP of 74HC595
uint16_t leds = 0;
uint8_t numberOfLEDsOn = 16; //Increase or decrease for start number of LEDS
bool add = false;
uint32_t lastTime;
uint8_t bitNum = numberOfLEDsOn - 1;
uint8_t count = 0;
void setup() {
pinMode(DATA_PIN, OUTPUT);
pinMode(CLOCK_PIN, OUTPUT);
pinMode(LATCH_PIN, OUTPUT);
Serial.begin(115200);
leds = 0; // Initially turns all the LEDs off, by giving the variable 'leds' the value 0
updateShiftRegister();
delay(500);
for (int i = 0; i < numberOfLEDsOn; i++) // Turn all the LEDs ON one by one.
{
bitSet(leds, i); // Set the bit that controls that LED in the variable 'leds'
updateShiftRegister();
delay(100);
}
}
uint16_t bits = 0;
void loop() {
if (millis() - lastTime > 100) {
lastTime = millis();
bits = random(0, 65536);
updateShiftRegister();
/*count ++;
if (count < 8) { //Increment at +=2/sec increase flash time
if (add) bitSet(leds, bitNum);
else bitClear(leds, bitNum);
updateShiftRegister();
add = !add;
}
else {
count = 0;
bitNum --;
add = false;
}*/
}
}
void updateShiftRegister()
{
digitalWrite(LATCH_PIN, LOW);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, highByte(bits));
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, lowByte(bits));
digitalWrite(LATCH_PIN, HIGH);
}