-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClockThread.py
38 lines (29 loc) · 1 KB
/
ClockThread.py
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
#!/usr/bin/python
import time
import datetime
import pytz
import threading
from Adafruit_7Segment import SevenSegment
class ClockThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.segment = SevenSegment(address=0x70)
self.stopping = False
def stop(self):
self.segment.disp.clear()
self.stopping = True
def run(self):
while not self.stopping:
now = datetime.datetime.now(pytz.timezone('Africa/Johannesburg'))
hour = now.hour
minute = now.minute
second = now.second
# Set hours
self.segment.writeDigit(0, int(hour / 10)) # Tens
self.segment.writeDigit(1, hour % 10) # Ones
# Set minutes
self.segment.writeDigit(3, int(minute / 10)) # Tens
self.segment.writeDigit(4, minute % 10) # Ones
# Toggle colon
# self.segment.set_colon(second % 2)
time.sleep(1)