diff --git a/basic_clock/main.py b/basic_clock/main.py new file mode 100644 index 0000000..7d2b8b4 --- /dev/null +++ b/basic_clock/main.py @@ -0,0 +1,46 @@ +"""An NTP time app""" +___name___ = "NTP time" +___license___ = "MIT" +___dependencies___ = ["ntp", "wifi", "app"] +___categories___ = ["EMF"] + +# borrowed from https://github.com/micropython/micropython/blob/master/esp8266/scripts/ntptime.py + +import ugfx, ntp, wifi, utime, machine, app +from tilda import Buttons +# initialize screen +ugfx.init() +ugfx.clear() + + + +# set the RTC using time from ntp +# print out RTC datetime + +if not wifi.is_connected(): + wifi.connect(show_wait_message=True) +ntp.set_NTP_time() +rtc = machine.RTC() +ugfx.orientation(270) +count = 0 +last = None +while 1: + now = rtc.now()[:6] + year = now[0] + month = now[1] + day = now[2] + hour = now[3] + minute = now[4] + second = now[5] + if now != last: + last = now + ugfx.clear() + ugfx.text(5, 5, "current time", ugfx.BLACK) + time_str = "%02i:%02i:%02i %i/%i/%4i" % (hour, minute, second, day, month, year) + ugfx.text(5, 20, time_str, ugfx.BLACK) + + if Buttons.is_pressed(Buttons.BTN_A) or Buttons.is_pressed(Buttons.BTN_B) or Buttons.is_pressed(Buttons.BTN_Menu): + break + utime.sleep_ms(10) +ugfx.clear() +app.restart_to_default() diff --git a/lib/sleep.py b/lib/sleep.py index 4c5e463..59e9b65 100644 --- a/lib/sleep.py +++ b/lib/sleep.py @@ -9,3 +9,7 @@ def sleep_ms(duration): def sleep(duration): utime.sleep(duration) + +def wfi(duration): + #todo: this is fake + sleep_ms(duration) diff --git a/time/main.py b/time/main.py deleted file mode 100644 index b267e95..0000000 --- a/time/main.py +++ /dev/null @@ -1,35 +0,0 @@ -"""An NTP time app""" -___name___ = "NTP time" -___license___ = "MIT" -___dependencies___ = ["ntp", "wifi"] -___categories___ = ["EMF"] - -# borrowed from https://github.com/micropython/micropython/blob/master/esp8266/scripts/ntptime.py - -import ugfx, ntp, wifi, utime, machine -# initialize screen -ugfx.init() -ugfx.clear() - - - -# set the RTC using time from ntp -# print out RTC datetime - -if not wifi.is_connected(): - wifi.connect(show_wait_message=True) -ntp.set_NTP_time() -rtc = machine.RTC() -ugfx.orientation(270) -while 1: - ugfx.text(5, 5, "current time", ugfx.BLACK) - year = rtc.now()[0] - month = rtc.now()[1] - day = rtc.now()[2] - hour = rtc.now()[3] - minute = rtc.now()[4] - second = rtc.now()[5] - time_str = "%02i:%02i:%02i %i/%i/%4i" % (hour, minute, second, day, month, year) - ugfx.text(5, 20, time_str, ugfx.BLACK) - utime.sleep(1) - ugfx.clear()