Quantcast
Channel: 丁才軒討論站
Viewing all articles
Browse latest Browse all 75

Python • EZ Start Kit+ Button A/B 測試

$
0
0
參考: https://sites.google.com/site/wenyunoti ... authuser=0

按鍵A, Kit+ 標號為 IO11, 對應 ESP32 對接為 GPIO 5 (即 Pin 5) ,初始值為 1 (BUTTON_UP)
按鍵B, Kit+ 標號為 IO15, 對應 ESP32 對接為 GPIO 36 (即 Pin 36)
ESP32 內建 LED為 對接為 GPIO 2 (即 Pin 2)

參考程式碼:

CODE:

from machine import Pin    #使用外部模組功能的動作叫做匯入 (import),匯入的有類別或函式,這邊是匯入Pin類別import time#ESP32 內建 LED 為 Pin 2 led = Pin(2, Pin.OUT)      #建立Pin物件,名稱叫led ,內建LED燈/OUTPUT#EZ Start Kit+ 的Button A 為 IO11, 對應 ESP32 為 GPIO 5buttonA = Pin(5, Pin.IN)    #A鍵/INPUT#EZ Start Kit+ 的Button B 為 IO15, 對應 ESP32 為 GPIO 36buttonB = Pin(36, Pin.IN)    #B鍵/INPUTBUTTON_UP = 1 #按鍵狀態為 UP (彈起)BUTTON_DOWN = 0 #按鍵狀態為 DOWN (下壓)#初始值print("Init A=", buttonA.value())print("Init led=", led.value())#停5秒,以便觀察time.sleep(5)print("set led on")led.on()                   #led.value(1) 也可以print("led=", led.value())time.sleep(5)while True:    if buttonA.value() == BUTTON_DOWN:        led.on()    else:        led.off()   #BUTTON_UP 時
執行時的輸出畫面:

CODE:

Init A= 1Init led= 0set led onled= 1

統計資料: 發表於 由 dtchang — 2023-11-24, 18:25



Viewing all articles
Browse latest Browse all 75

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>