Advent Calendar for the PiFace Control And Display
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import datetime | |
import pifacecad | |
from datetime import timedelta | |
now = datetime.date.today() | |
print(now) | |
# if you need to change the date to test your code, then add a number of days to the date by uncommenting the line below | |
# now = now + timedelta(days=10) | |
# binary values to create bitmaps for a bell, a present and a star. | |
images = [ [0b00100, | |
0b01110, | |
0b01110, | |
0b01110, | |
0b11111, | |
0b00000, | |
0b00100, | |
0b00000], | |
[0b00000, | |
0b01010, | |
0b00100, | |
0b11111, | |
0b10101, | |
0b11111, | |
0b10101, | |
0b11111], | |
[0b00000, | |
0b00100, | |
0b10101, | |
0b01110, | |
0b11111, | |
0b01110, | |
0b10101, | |
0b00100], | |
] | |
# use this website to design your own bitmaps (set character size to '5 by 8') | |
# http://www.quinapalus.com/hd44780udg.html | |
cad = pifacecad.PiFaceCAD() | |
if now.month ==12: # if december | |
day = now.day | |
if day < 26: | |
image = pifacecad.LCDBitmap(images[day%len(images)]) # create bitmap | |
cad.lcd.store_custom_bitmap(0,image) # store bitmap | |
cad.lcd.write_custom_bitmap(0) # write bitmap to screen | |
cad.lcd.backlight_on() | |
cad.lcd.cursor_off() | |
cad.lcd.blink_off() | |
if day == 25: # if christmas | |
greeting = " Merry \nChristmas" | |
cad.lcd.write(greeting) | |
else: | |
daysTillChristmas = 25 - day | |
if daysTillChristmas == 1: # if there is 1 day till christmas, we say 'day' instead of 'days' | |
pluralisation = "" | |
else: | |
pluralisation = "s" | |
greeting = " {} day{} till \n Christmas".format(daysTillChristmas, pluralisation) # {} are replaced by the variables in format in order | |
print(greeting) | |
cad.lcd.write(greeting) | |
else: | |
greeting = "One year to go!" # if its december but christmas has been. maybe add boxing day new years day? | |
print(greeting) | |
cad.lcd.write(greeting) | |
else: | |
greeting = "Not December yet" | |
print(greeting) | |
cad.lcd.write(greeting) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment