Skip to content

Commit 489c9f4

Browse files
committed
Add script to print the date and time
1 parent 751850d commit 489c9f4

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

datetime.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/python3
2+
# pylint: disable=E1101,W0614
3+
4+
import time
5+
from Adafruit_Thermal import *
6+
7+
i_feed = 4
8+
f_pause = 1.0
9+
10+
printer = Adafruit_Thermal("/dev/serial0", 19200, timeout=5)
11+
12+
datestamp = time.strftime("%Y-%m-%d", time.gmtime())
13+
print ("Date in preferred format:", datestamp)
14+
timestamp = time.strftime("%H:%M:%S", time.gmtime())
15+
print ("Time in preferred format:", timestamp)
16+
17+
# Give a little room at the top
18+
printer.feed(i_feed)
19+
# Center justify
20+
printer.justify('C')
21+
# Large size
22+
printer.setSize('L')
23+
# Print the date
24+
printer.println(datestamp)
25+
# Print the time
26+
printer.println(timestamp)
27+
# Give a little room at the bottom
28+
printer.feed(i_feed)
29+
30+
# Tell printer to sleep
31+
printer.sleep()
32+
# Call wake() before printing again, even if reset
33+
printer.wake()
34+
# Restore printer to defaults
35+
printer.setDefault()
36+
37+
# Sleep for one second in case we're called many times
38+
time.sleep(f_pause)

0 commit comments

Comments
 (0)