系统信息:
Raspberry Pi Zero 2W
系统版本: 2024-10-22-raspios-bullseye-armhf
Python 版本:Python 3.9.2
已安装 pip3
支持拍摄 1080p 30 (1092*1080), 720p 60 (1280*720), 60/90 (640*480)
已安装 vim
已安装 git
学习目标:
- 点亮三色 LED
学习内容:
python">import RPi.GPIO as GPIO
import timedef main():"""点亮三色 LED """rled_pin = 32 # GPIO 12 红gled_pin = 12 # GPIO 18 绿bled_pin = 33 # GPIO 13 蓝blink_count = 0 # 计数器pin_list = [rled_pin, gled_pin, bled_pin] # 列表# 初始化GPIO.setmode(GPIO.BOARD) # BOARD 编码GPIO.setup(pin_list, GPIO.OUT) # 输出模式GPIO.output(pin_list, GPIO.LOW) # LOW 低电平try:# 循环闪烁 RGBwhile blink_count < 2:blink_count += 1# 红GPIO.output(rled_pin, GPIO.HIGH) # 亮红time.sleep(0.1)GPIO.output(rled_pin, GPIO.LOW) # 灭红time.sleep(0.1)# 绿GPIO.output(gled_pin, GPIO.HIGH) # 亮绿time.sleep(0.1)GPIO.output(gled_pin, GPIO.LOW) # 灭绿time.sleep(0.1)# 蓝GPIO.output(bled_pin, GPIO.HIGH) # 亮蓝time.sleep(0.1)GPIO.output(bled_pin, GPIO.LOW) # 灭蓝time.sleep(0.1)finally:# 清理引脚规则print("--- 关闭 ---")GPIO.output(pin_list, GPIO.LOW) # LOW 低电平GPIO.cleanup() # 释放 GPIO 资源,清除引脚规则if __name__ == "__main__":main()