[Let'sDo第3期] DIY一个电子测光表 2 过程贴
主板资料:
1、https://www.adafruit.com/product/5691
2、https://learn.adafruit.com/esp32-s3-reverse-tft-feather
刷固件:
从官网下载Adafruit ESP32-S3主控板固件:https://circuitpython.org/board/adafruit_feather_esp32s3_reverse_tft
测试程序:
1)呼吸灯
import board import time from digitalio import DigitalInOut, Direction, Pull led = DigitalInOut(board.LED) led.direction = Direction.OUTPUT while True: led.value = True time.sleep(0.5) led.value = False time.sleep(0.5)
2)点亮屏幕
import board import terminalio from adafruit_display_text import label text = "Hello world" text_area = label.Label(terminalio.FONT, text=text) text_area.x = 10 text_area.y = 10 board.DISPLAY.root_group = text_area while True: Pass
3)转舵机
import time import board import pwmio from adafruit_motor import servo # create a PWMOut object on Pin D5. pwm = pwmio.PWMOut(board.D5, duty_cycle=2 ** 15, frequency=50) # Create a servo object, my_servo. my_servo = servo.Servo(pwm) while True: for angle in range(0, 180, 1): # 0 - 180 degrees, 5 degrees at a time. my_servo.angle = angle time.sleep(0.01) for angle in range(180, 0, -1): # 180 - 0 degrees, 5 degrees at a time. my_servo.angle = angle time.sleep(0.01)
4)测光照
import time import board import adafruit_bh1750 i2c = board.I2C() sensor = adafruit_bh1750.BH1750(i2c) while True: print("%.2f Lux"%sensor.lux) time.sleep(1)
GIT其他示例资料:
点灯示例
https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CircuitPython_Essentials/CircuitPython_Digital_In_Out/code.py
屏幕示例
https://github.com/adafruit/Adafruit_CircuitPython_Display_Text (显示库)
https://learn.adafruit.com/esp32-s3-reverse-tft-feather/displayio-example
光照示例
https://github.com/adafruit/Adafruit_CircuitPython_BH1750
舵机示例
https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/CircuitPython_Essentials/CircuitPython_Servo/code.py
https://github.com/adafruit/Adafruit_CircuitPython_Motor (舵机库)