本站改版新增arduino频道
import machine from machine import Pin, I2C, RTC,Timer import network import utime import ntptime def sync_ntp(): ntptime.NTP_DELTA = 3155644800 # 可选 UTC+8偏移时间(秒),不设置就是UTC0 ntptime.host = 'ntp1.aliyun.com' # 可选,ntp服务器,默认是"pool.ntp.org" ntptime.settime() # 修改设备时间,到这就已经设置好了 week = ['Monday', 'Tuesday', 'Wednesay', 'Thursday', 'Friday', 'Saturday', 'Sunday'] time_list = ['', '', ''] rtc = RTC() #连接网络 station = network.WLAN(network.STA_IF) while(not station.isconnected()): station.active(True) try: station.connect("xxxxxx", "xxxxx") utime.sleep(5.0) except OSError: print("OSError") utime.sleep(2.0) sync_ntp() # 已经设置好了,随便用 from machine import RTC rtc = RTC() print(rtc.datetime()) while True: datetime = rtc.datetime() # 获取当前时间 print('CLOCK!') print(str(datetime[0]) + '-' + str(datetime[1]) + '-' + str(datetime[2]) + ' ' + week[datetime[3]]) # 显示时间需要判断时、分、秒的值否小于 10,如果小于 10,则在显示前面补“0”以 # 达到较佳的显示效果 for i in range(4, 7): if datetime[i] < 10: time_list[i - 4] = "0" else: time_list[i - 4] = "" # 显示时间 print(time_list[0] + str(datetime[4]) + ':' + time_list[1] + str(datetime[5]) + ':' + time_list[2] + str(datetime[6])) utime.sleep(1.0)
Copyright © 2014 ESP56.com All Rights Reserved
晋ICP备14006235号-22 晋公网安备14108102001165号
执行时间: 0.0096409320831299 seconds