Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5273

Beginners • Re: SH1106 128x64 OLED Display on I2C in Raspberry Pi OS Bookworm

$
0
0
This displays the date at the top, with the time below in large monospaced characters filling the screen width which is exactly what I was after.
Well, that is great.
There is something which makes me unhappy (fonts do not change over time)
I would rewrite

Code:

# Display loopwhile True:# Get time & datetime = datetime.now().strftime("%H:%M")date = datetime.now().strftime("%d/%m/%y")# Select font(s) and draw to displaywith canvas(device) as draw:FontTemp = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf",21)draw.text((12,  -4), (date), font = FontTemp, fill="white")FontTemp = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf",42)draw.text((0, 25), (time), font=FontTemp, fill="white")       sleep(1)
to (easier to adapt/read)

Code:

FontTempNormal = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf",21)FontTempBold = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf",42)# Display loopwhile True:# Get time & datetime = datetime.now().strftime("%H:%M")date = datetime.now().strftime("%d/%m/%y")# Select font(s) and draw to displaywith canvas(device) as draw:draw.text((12, -4), (date), font=FontTempNormal, fill="white")draw.text((0, 25), (time), font=FontTempBold, fill="white")       sleep(1)

Statistics: Posted by dbrion1 — Tue Mar 19, 2024 5:53 pm



Viewing all articles
Browse latest Browse all 5273

Trending Articles