再次感谢DigiKey和EEworld组织的Follow me 第2期活动,让我零成本入门Adafruit ESP32-S3 TFT Feather
第一部分
汇报视频- 【得捷电子Follow me第2期】视频汇报-EEWORLD大学堂
第二部分
此处我将四个任务整合在了一个文件里,便于提交,源码中有分别完成的任务
效果展示:
汇总代码如下
- import board, displayio
- import rtc, wifi, ssl
- import time as Time
- import socketpool
- import neopixel
- from digitalio import DigitalInOut, Direction, Pull
- import adafruit_imageload
- import adafruit_ntp
- import adafruit_requests
- from adafruit_display_text import label
- from adafruit_bitmap_font import bitmap_font
-
-
-
- wifi.radio.start_ap('Follow_me_Tasks', 'EEworld00')
- print("Hotspot Launched")
-
-
-
- display = board.DISPLAY
- group = displayio.Group()
-
- def lableimage(path):
- image, palette = adafruit_imageload.load(path)
- return displayio.TileGrid(image, pixel_shader=palette)
-
-
- font = bitmap_font.load_font("/font/sytq_16.pcf")
- timef = bitmap_font.load_font("/font/time.bdf")
-
- def labletext(x, y, text, font=font, color=0x000000):
- return label.Label(font, text=text, color=color, x=x, y=y)
-
-
- grid = lableimage("/img/ddw.png")
- group.append(grid)
-
-
-
- date = labletext(48, 20, "0月0日")
- day = labletext(150, 20, "周八")
- time = labletext(22, 58, "00:00", font=timef)
- weather = labletext(12, 112, "?")
- temp = labletext(198, 112, "00°")
-
- group.append(date)
- group.append(day)
- group.append(time)
- group.append(weather)
- group.append(temp)
-
-
-
- pool = socketpool.SocketPool(wifi.radio)
- ntp = adafruit_ntp.NTP(pool, tz_offset=8, server="ntp.aliyun.com")
- rtc.RTC().datetime = ntp.datetime
-
- requests = adafruit_requests.Session(pool, ssl.create_default_context())
-
- def get_weather():
- city = "120101"
- key = "cc46b036804b84ce5b7b76d9a0511c68"
- url = "https://restapi.amap.com/v3/weather/weatherInfo?city=" + city + "&key=" + key
- response = requests.get(url)
- json_resp = response.json()
- response.close()
- return json_resp["lives"][0]["temperature"], json_resp["lives"][0]["weather"]
-
-
- pixel_pin = board.NEOPIXEL
- pixels = neopixel.NeoPixel(pixel_pin, 1, brightness=0.1, auto_write=False)
-
- def pixelsetcolor(c):
- pixels[0] = c
- pixels.show()
-
-
- btn = DigitalInOut(board.BOOT0)
- btn.direction = Direction.INPUT
- btn.pull = Pull.UP
-
- color = 0
-
- days = ["周一","周二","周三","周四","周五","周六","周日"]
- state = "init"
-
-
- while True:
-
- n = Time.localtime()
- if (state == "init" or n.tm_min == 0):
- date.text = "%d月%d日" % (n.tm_mon, n.tm_mday)
- day.text = days[n.tm_wday]
- t, w = get_weather()
- weather.text = w
- temp.text = "%s°" % (t)
- state = "running"
-
- time.text = "%02d:%02d" % (n.tm_hour, n.tm_min)
- display.show(group)
-
-
- if not btn.value:
- if color % 8 == 0:
- pixelsetcolor(0xFF0000)
- print("Pixel is R")
- elif color % 8 == 1:
- pixelsetcolor(0x00FF00)
- print("Pixel is G")
- elif color % 8 == 2:
- pixelsetcolor(0x0000FF)
- print("Pixel is B")
- elif color % 8 == 3:
- pixelsetcolor(0xFFFF00)
- print("Pixel is Yellow")
- elif color % 8 == 4:
- pixelsetcolor(0xFF00FF)
- print("Pixel is Megenta")
- elif color % 8 == 5:
- pixelsetcolor(0x00FFFF)
- print("Pixel is Cyan")
- elif color % 8 == 6:
- pixelsetcolor(0xFFFFFF)
- print("Pixel is Light")
- elif color % 8 == 7:
- pixelsetcolor(0x000000)
- print("Pixel is Dark")
- color += 1
- else:
- pass
- Time.sleep(0.2)
第三部分
源码下载:download.eeworld.com.cn/detail/bjm212501/629534
|