|
本帖最后由 mao_jin_dao 于 2020-4-13 21:24 编辑
功能显示时钟 实物图
CODE引入tm1637.py
文件见micropython-tm1637
main.py- from machine import Pin, I2C
- import urequests as requests
- import network
- import time
- import tm1637
- def connectionWifi():
- wlan = network.WLAN(network.STA_IF)
- wlan.active(True)
- wlan.connect('ssid', 'password')
- while True:
- if not wlan.isconnected():
- time.sleep_ms(500)
- else:
- print('connected to network')
- break
- def getJsonInfoFromURL(url):
- response = requests.get(url)
- return response.json()
- def tm1637_LED(hours, minutes):
- if hours >= 23 or hours <=6:
- tm.brightness(1)
- else:
- tm.brightness(6)
- tm.numbers(hours, minutes)
- if __name__== '__main__':
- time_api="http://ip:8080/bills/ESP8266TimeAPI"
- connectionWifi()
- tm = tm1637.TM1637(clk=Pin(5), dio=Pin(4))
- while True:
- try:
- result = getJsonInfoFromURL(time_api)
- tm1637_LED(result['hours'], result['minutes'])
- time.sleep_ms(30000)
- except:
- connectionWifi()
复制代码
参考文档
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
打赏
-
查看全部打赏
|