Raspberry Pi Birthday Countdown

Posted on 31/01/2015 by Brian Corteil Posted in Making, Raspberry Pi

On the 28th feb will be the Raspberry Pi’s 3rd Birthday. I wrote a plugin for Pimoroni’s cool Displayotron for the Raspberry Pi, details for the plugin can be found on the Pimoroni forum here.

command_line_count_down

I have just finished converting the code for counting down on the command line, you can download the code from my github account by entering the following command on your Raspberry Pi’s command line.

git clone https://github.com/Corteil/countDown.git

then change the working directory

cd ./countDown

and then run the code

python countDown.py

or you can type the code in, using a text editor, the code is below

#
#count down timer
#
# by Brian Corteil aka on Twitter @CannonFodder
#
# free to use
#

import sys
import os,time, datetime
from datetime import timedelta
# enter target time and date here

day=28
month=02
year=2015
hour=16
minutes=30
sec=0
targetTime = datetime.datetime(year, month, day, hour, minutes) # sets up target time
timeNow =datetime.datetime.now()

while timeNow <= targetTime:

    timeNow =datetime.datetime.now() # the time now!
    remainingTime=(targetTime-timeNow)
    days = remainingTime.days
    secs = remainingTime.seconds
    hrs, secs = divmod(secs, 3600)
    mins, secs = divmod(secs, 60)

 sys.stdout.write(“\r%dd %dh %dm %ds to the Raspberry Pi Birthday Bash! ” % (days, hrs, mins, secs))

    sys.stdout.flush()
    time.sleep(1)

print (“\rwhat time is it? It’s Party Time”) # prints Party Time