EasyManua.ls Logo

SunFounder ESP32

Default Icon
771 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
SunFounder ESP32 Starter Kit
(continued from previous page)
rclk.off()
# Iterate through each bit (from 7 to 0)
for bit in range(7, -1, -1):
# Extract the current bit from the input data
value = 1 & (dat >> bit)
# Set the SRCLK pin to low
srclk.off()
# Set the value of the SDI pin
sdi.value(value)
# Clock the current bit into the shift register by setting the SRCLK pin to high
srclk.on()
# Latch the data into the storage register by setting the RCLK pin to high
rclk.on()
# Continuously loop through the numbers 0 to 9 and display them on the 7-segment display
while True:
for num in range(10):
hc595_shift(SEGCODE[num]) # Shift the segment code for the current number into
˓the 74HC595
time.sleep_ms(500) # Wait 500 milliseconds before displaying the next number
When the script is running, you will be able to see the LED Segment Display display 0~9 in sequence.
How it works?
In this project, we are using the hc595_shift() function to write the binary number to the shift register.
Suppose that the 7-segment Display display the number “2”. This bit pattern corresponds to the segments f, c and dp
being turned off (low), while the segments a, b, d, e and g are turned on (high). This is “01011011” in binary and
“0x5b” in hexadecimal notation.
Therefore, you would need to call hc595_shift(0x5b) to display the number “2” on the 7-segment display.
328 Chapter 3. For MicroPython User

Table of Contents