Skip to content

Instantly share code, notes, and snippets.

@the6th
Last active July 19, 2020 15:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save the6th/a114055e3c0160d4ea781bf83678c537 to your computer and use it in GitHub Desktop.
Save the6th/a114055e3c0160d4ea781bf83678c537 to your computer and use it in GitHub Desktop.
Digital Clock on M5stack JST
# 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