//https://www.rapidtables.com/convert/number/binary-to-decimal.html?x=1111100000
//https://ledcalculator.net/#p=5&v=3&c=10&n=1&o=w
#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 = 10; //Increase or decrease for start number of LEDS
void ledDisplay() {
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);
}
for (int i = 9; i > -1; i--) // Turn all the LEDs OFF one by one.
{
bitClear(leds, i); // Set the bit that controls that LED in the variable 'leds'
updateShiftRegister();
delay(100);
}
for (int i = 9; i > -1; 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);
}
for (int i = 0; i < numberOfLEDsOn; i++) // Turn all the LEDs ON one by one.
{
bitClear(leds, i); // Set the bit that controls that LED in the variable 'leds'
updateShiftRegister();
delay(100);
}
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();
bitClear(leds, i);
delay(100);
}
for (int i = 9; i > -1; i--) // Turn all the LEDs OFF one by one.
{
bitSet(leds, i); // Set the bit that controls that LED in the variable 'leds'
updateShiftRegister();
bitClear(leds, i);
delay(100);
}
for (int i = 0; i < 3; i ++) {
leds = 341;
updateShiftRegister();
delay(300);
leds = 682;
updateShiftRegister();
delay(300);
}
for (int i = 0; i < 3; i ++) {
leds = 1023;
updateShiftRegister();
delay(300);
leds = 0;
updateShiftRegister();
delay(300);
}
for (int i = 0; i < 3; i ++) {
leds = 31;
updateShiftRegister();
delay(300);
leds = 992;
updateShiftRegister();
delay(300);
}
}
void updateShiftRegister()
{
digitalWrite(LATCH_PIN, LOW);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, highByte(leds));
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, lowByte(leds));
digitalWrite(LATCH_PIN, HIGH);
}
void setup() {
pinMode(DATA_PIN, OUTPUT);
pinMode(CLOCK_PIN, OUTPUT);
pinMode(LATCH_PIN, OUTPUT);
}
void loop() {
ledDisplay();
delay(1000);
}