In the previous section, we already learned how to display four digits on a 7-segment module and wrote the program for displaying a 4-digit number (ch02_04.py
). In this section, we continue to build a simple program for a countdown timer using a 4-digit 7-segment module and two 74HC595 shift registers.
Our scenario is to get a number input from the user, for instance, 30. After this, the number is displayed on the module. Then, we decrease the number down to 0.
Let's copy the ch02_04.py
file and then modify it as follows:
# ch02_05.py … … print("Running...") number_s = raw_input("Enter a number (1-999): ") number = int(number_s) print("Countdown " + number_s) try: timer = 0 while 1: digit = number LED_display(0, digit % 10, 0) digit /= 10 time.sleep(0.01) LED_display(1, digit % 10, 0) time.sleep(0.01) digit /= 10 LED_display(2, digit % 10, 0) time.sleep(0.01) digit /= 10 ...