Last active
July 19, 2020 15:25
-
-
Save the6th/a114055e3c0160d4ea781bf83678c537 to your computer and use it in GitHub Desktop.
Digital Clock on M5stack JST
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
# https://github.com/m5stack/M5Cloud/blob/master/examples/DigitalClock/clock.py | |
# The default timezone on M5stack is CST(+8,China) | |
# change timezone to JST(+9) | |
from m5stack import * | |
import time, _thread, machine | |
def clock(): | |
rtc = machine.RTC() | |
print("Synchronize time from NTP server ...") | |
lcd.println("Synchronize time from NTP server ...") | |
rtc.ntp_sync(server="ntp.nict.jp", tz='JST-9') | |
lcd.clear() | |
lcd.setBrightness(200) | |
lcd.font(lcd.FONT_7seg, fixedwidth=True, dist=16, width=2) | |
while True: | |
d = time.strftime("%Y-%m-%d", time.localtime()) | |
t = time.strftime("%H:%M:%S", time.localtime()) | |
lcd.print(d, lcd.CENTER, 50, lcd.ORANGE) | |
lcd.print(t, lcd.CENTER, 130, lcd.ORANGE) | |
time.sleep(1) | |
_thread.start_new_thread('Clock', clock, ()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment