In lesson 42 we showed you how to connect and program the 74HC595 shift register. We showed how data in byte format would then be written to an array of 8 LED to give a visual representation of the binary version of that byte variable. We then gave you the assignment to create a Binary Counter using the 4HC595. In this lesson we show you the solution. This builds on Lesson 42, so make sure to have your basic 74HC595 circuit set up before starting this lesson.
In this lesson we are using parts from the Elegoo Arduino kit, which you can get HERE.
The code we ended up developing in this lesson is provided below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | int latchPin=11; int clockPin=9; int dataPin=12; int dt=1000; byte LED1s=0b00000000; void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(latchPin,OUTPUT); pinMode(dataPin,OUTPUT); pinMode(clockPin,OUTPUT); } void loop() { // put your main code here, to run repeatedly: digitalWrite(latchPin,LOW); shiftOut(dataPin,clockPin,LSBFIRST,LED1s); digitalWrite(latchPin,HIGH); Serial.println(LED1s,BIN); delay(dt); LED1s=LED1s+1; } |