独角兽企业重金招聘Python工程师标准>>>
1.1 组装好你的树莓派
组装工作之后再讲述
控制二极管发光及关闭
组装完成后,我们开始第一个例子:控制二极管发光及关闭的小程序
一下内容保存在diode_on_off.py文件中
import RPi.GPIO ad GPIO#不再提示警告GPIO.setwarnings(False)#设置GPIO模式为物理引脚GPIO.setmode(GPIO.BOARD)GPIO.setwarnings(False)#设置两个物理引脚 19 和 21 一个高电平 一个低电平 输入电压让二极管发光gpio_left = 19gpio_right = 21GPIO.setup(gpio_left, GPIO.OUT)GPIO.setup(gpio_right, GPIO.OUT)def on():GPIO.output(gpio.left, GPIO.HIGH)GPIO.output(gpio.right, GPIO.LOW)def off():GPIO.output(gpio.left, GPIO.LOW)GPIO.output(gpio.left, GPIO.LOW)while True:print("1 to on")print("0 to off")print("q to exit")user_choice = input("Choice:")if user_choice == "1":on()elif user_choice == "0":off()elif (user_choice == "q") or (user_choice == "Q") :GPIO.cleanup()breakelse:print("Enter Error")
pi@xiaoxiao:~/workspace $ python3 Test/diode_on_off.py1 to on0 to offq to exitChoice:11 to on0 to offq to exitChoice:2Enter Error1 to on0 to offq to exitChoice:qpi@xiaoxiao:~/workspace $
第二个例子:打开相机及拍照
1.2 可能遇到的问题
1.3 树莓派快速指南
1.4Python3
1.5 小结
如果觉得《树莓派Python编程指南--第一章(起航--启动和运行)》对你有帮助,请点赞、收藏,并留下你的观点哦!