Elegoo Starter Kit Lesson 16: Eight LED with 74HC595

Newbie here;

Working my way through the kit. Would like to modify the code in Example 16 from watching LEDS light as a counter goes from 0-7, to watching the LEDS count in binary from 0-255. Can somebody point me in the right direction for the needed functions to add to the code? Or maybe the code is already out there?

I don't know how the "example 16" looks like.

Manual to post code:
go to Arduino IDE with your code
do a rightclick
choose "copy for forum" from the context menu
switch to browser
paste clipboard into textwindow

one basic idea is

define a variable to count

byte MyCounter
count up the variable from 0 to 255

define variables for each of the 8 LEDs
byte LED0, LED1, LED2 .. LED7

do a bitwise AND-operation to filter the related bit

LED0 = MyCounter & 1;
LED1 = MyCounter & 2;
LED2 = MyCounter & 4;
LED3 = MyCounter & 8;
LED4 = MyCounter & 16;
LED5 = MyCounter & 32;
LED6 = MyCounter & 64;
LED7 = MyCounter & 128;

check if bit is set if bit is set switch on related LED

If (LED0 == 1) {
"switch on LED 0"
}

If (LED1 == 2) {
"switch on LED 1"
}

If (LED2 == 4) {
"switch on LED 2"
}

etc.

best regards Stefan

StefanL38;

Thx for your reply, it helped me look in the right direction.

Ex 16 in the Elegoo starter kit shows code to turn on bits 0-7 of 8 leds at the outputs of 74hc595 using the bitSet command. One led at a time. I tried to attach a movie of the result (shift register.mp4); size limitation.

I wanted to see something more interesting like the led displays for counting 0-255. The code I wrote is attached (my_eight_led_with_74hc595.ino).

The movie of the result is attached (binary counting.mp4) wont let me. One thing I learned is the kit has you set up the leds with the lsb at the left which is visually wrong. It should be on the right. Fun anyway.

MY_EIGHT_LED_WITH_74HC595_2.ino (832 Bytes)