Reader small image

You're reading from  Raspberry Pi LED Blueprints

Product typeBook
Published inSep 2015
Publisher
ISBN-139781782175759
Edition1st Edition
Right arrow
Author (1)
Agus Kurniawan
Agus Kurniawan
author image
Agus Kurniawan

Agus Kurniawan is an independent technology consultant, author, and lecturer. He has over 18 years' experience working on various software development projects, including delivering training courses and workshops, and delivering technical writing. He has done a few research activities related to wireless networking, software, and security in multiple universities. Currently, he is pursuing a Ph.D. program in Computer Science in Germany. He has previously written five books for Packt.
Read more about Agus Kurniawan

Right arrow

Building a countdown timer


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

...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Raspberry Pi LED Blueprints
Published in: Sep 2015Publisher: ISBN-13: 9781782175759

Author (1)

author image
Agus Kurniawan

Agus Kurniawan is an independent technology consultant, author, and lecturer. He has over 18 years' experience working on various software development projects, including delivering training courses and workshops, and delivering technical writing. He has done a few research activities related to wireless networking, software, and security in multiple universities. Currently, he is pursuing a Ph.D. program in Computer Science in Germany. He has previously written five books for Packt.
Read more about Agus Kurniawan