系统信息:
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
学习内容:
import RPi.GPIO as GPIO
import timedef main():"""点亮一个 LED """led_pin = 32 # GPIO 12blink_count = 0 # 计数器# 初始化GPIO.setmode(GPIO.BOARD) # BOARD 编码GPIO.setup(led_pin, GPIO.OUT) # 输出模式GPIO.output(led_pin, GPIO.LOW) # LOW 低电平try:# 循环闪烁while blink_count < 2:blink_count += 1print("--- LED ON ---")GPIO.output(led_pin, GPIO.HIGH) # HIGH 高电平time.sleep(0.5)print("--- LED OFF ---")GPIO.output(led_pin, GPIO.LOW) # LOW 低电平time.sleep(0.5)finally:# 清理引脚规则GPIO.output(led_pin, GPIO.LOW) # LOW 低电平GPIO.cleanup() # 释放 GPIO 资源,清除引脚规则if __name__ == "__main__":main()
学习参考:
- GPIO