# Import required modules
# 導入所需模組
import machine, time
# Initialize a Pin object for GPIO 32 as an input pin
# without pull-up or pull-down resistor
# 初始化 GPIO 32 的 Pin 物件為輸入腳位,不使用上拉或下拉電阻
switch = machine.Pin(32, machine.Pin.IN, pull=None)
# Title: Demonstrating Floating State on a GPIO Pin
# 標題: 展示 GPIO 腳位的浮動狀態
# Description: This code reads and prints the state of a pin configured as input
# without any pull-up or pull-down resistor.
# The floating state of the pin will be observable as the printed value may change
# without consistent pattern when the pin is not driven.
# 描述: 這段程式碼會讀取並印出設定為輸入而沒有任何上拉或下拉電阻的腳位的狀態。
# 當腳位未被驅動時,可以觀察到腳位的浮動狀態,因為印出的值可能會在沒有一致模式下變動。
while True:
# Read and print the value of the pin
# 讀取並印出腳位的值
print("Pin 32 value: ", switch.value())
# Pause for 500 milliseconds before reading the pin again
# 再次讀取腳位前暫停 500 毫秒
time.sleep_ms(200)