
按键电路, 我这边接到 Circuitpython Name 的D5,D6
代码如下
import timeimport boardfrom digitalio
import DigitalInOut, Direction, Pull
led = DigitalInOut(board.LED)
led.direction = Direction.OUTPUT
switch = DigitalInOut(board.D5) # For Feather M0 Express, Feather M4 ExpressRedswitch = DigitalInOut(board.D6) # For Circuit Playground Expressswitch.direction = Direction.INPUT
Redswitch.direction = Direction.INPUT
Redswitch.pull = Pull.UP
switch.pull = Pull.UPwhile True: # We could also do "led.value = not switch.value"!
if switch.value:
led.value = False
else:
led.value = True
if Redswitch.value:
print("no press")
else:
print("pressed")
time.sleep(0.01) # debounce delay2.BH1750 光照强度传感器电路连接。BH1750 电路通过 STEMMA的 那个QT连接器进行连接。
SDA-----GPIO42
SCL-----GPIO41
5V ---- VSENSOR
GND----GND
BH1750 的 I2C 通过手册可知是0x23 指令集

借助与于adafruit 的库,可以很方便的进行读取传感器数据
import time
import board
import adafruit_bh1750
#i2c = board.I2C()
# uses board.SCL and board.SDA
i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
sensor = adafruit_bh1750.BH1750(i2c)
while True:
print("%.2f Lux" % sensor.lux)
time.sleep(1)3.屏幕显示

屏幕控制芯片是ST7789,是一个 240X135 的 TFT屏幕 通过SPI引脚与ESP32-S3 进行通信
TFTPOWR ====GPIO21
TFT_CS ===== GPIO7
TFT_DC ====== GPIO39 TFT_RESET ==== GPIO40 TFT_BACKLIGHT =====GPIO45
点了屏幕代码
import board import terminalio from adafruit_display_text import label text = "Hello EEPW & DigiKey" text_area = label.Label(terminalio.FONT, text=text) text_area.x = 60 text_area.y = 60 board.DISPLAY.root_group = text_area while True: pass
测试图片 点亮屏幕

光照度与按键测试

我要赚赏金
