树莓派python编程怎么运行_树莓派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 = 19

gpio_right = 21

GPIO.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()

break

else:

print("Enter Error")

pi@xiaoxiao:~/workspace $ python3 Test/diode_on_off.py

1 to on

0 to off

q to exit

Choice:1

1 to on

0 to off

q to exit

Choice:2

Enter Error

1 to on

0 to off

q to exit

Choice:q

pi@xiaoxiao:~/workspace $

第二个例子:打开相机及拍照

1.2 可能遇到的问题

1.3 树莓派快速指南

1.4Python3

1.5 小结

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值