forked from jerry-git/learn-python3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patholed-worldclock2.py
More file actions
44 lines (32 loc) · 1.1 KB
/
oled-worldclock2.py
File metadata and controls
44 lines (32 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import datetime
import pytz
def text():
timezones = (
'Asia/Hong_Kong',
'America/New_York',
'Europe/London',
)
fmt = '%m-%d %H:%M:%S'
now = datetime.datetime.now()
text = "World Clock\n"
for tz_name in timezones:
tz = pytz.timezone(tz_name)
tz_now = now.astimezone(tz)
output = '{tz_name}:{tz_now_str}'.format(
tz_name = tz_name.split("/")[1],
tz_now_str = tz_now.strftime(fmt)
)
text = text + output + "\n"
return text
from luma.core.interface.serial import i2c, spi, pcf8574
from luma.core.interface.parallel import bitbang_6800
from luma.core.render import canvas
from luma.oled.device import ssd1306, ssd1309, ssd1325, ssd1331, sh1106, ws0010
from PIL import ImageFont
serial = i2c(port=1, address=0x3C)
device = sh1106(serial)
font1 = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf',8)
while True:
with canvas(device) as draw:
draw.rectangle(device.bounding_box, outline="white", fill="black")
draw.text((0, 0), text(), fill="white", font=font1)