2596| 7
|
【临沂】第一课 python编程——控制LED灯 |
程序一:点亮树莓派5号LED灯并熄灭 [mw_shl_code=python,false]import RPi.GPIO as Pi import time led = 5 Pi.setwarnings(False) Pi.setmode(Pi.BCM) Pi.setup(led,Pi.OUT) Pi.output(led,Pi.HIGH) time.sleep(0.5) Pi.output(led,Pi.LOW)[/mw_shl_code] 程序二:控制树莓派5号LED灯闪烁 [mw_shl_code=python,false]import RPi.GPIO as Pi import time led = 5 Pi.setwarnings(False) Pi.setmode(Pi.BCM) Pi.setup(led,Pi.OUT) while True: Pi.output(led,Pi.HIGH) time.sleep(0.5) Pi.output(led,Pi.LOW) time.sleep(0.5)[/mw_shl_code] 程序三:循环闪烁多盏LED灯 [mw_shl_code=python,false]import RPi.GPIO as Pi import time led = 5,6,12,16 Pi.setwarnings(False) Pi.setmode(Pi.BCM) Pi.setup(led,Pi.OUT) while True: Pi.output(led,Pi.HIGH) time.sleep(0.5) Pi.output(led,Pi.LOW) time.sleep(0.5)[/mw_shl_code] 程序四:单向流水灯 [mw_shl_code=python,false]import RPi.GPIO as Pi import time leds = 5,6,12,16 Pi.setwarnings(False) Pi.setmode(Pi.BCM) Pi.setup(leds,Pi.OUT) while True: for i in range(4): Pi.setput(leds,Pi.HIGH) time.sleep(0.5) Pi.setput(leds,Pi.LOW)[/mw_shl_code] 程序五:往返流水灯 [mw_shl_code=python,false]import RPi.GPIO as Pi import time leds = 5,6,12,16,12,6 Pi.setwarnings(False) PI.setmode(Pi.BCM) Pi.setup(leds,Pi.OUT) while True: for i in range(6): Pi.output(leds,Pi.HIGH) time.sleep(0.5) Pi.output(leds,Pi.LOW)[/mw_shl_code] 搞纯粹的东西果然很累,这些代码也肯定不可能一次成功,里面肯定有些小错误,这也是纯手打的弊端,看样子还是复制粘贴好用。我们不仅要拿来,还得有所创新,这样我们才能在前人的基础上继续走的更高更远。 |
pATAq 发表于 2020-4-25 01:21 版主,这个gpiozero库我知道,但是您说的演示是什么个情况,能否详细说一下,或者有专门的介绍帖子让我观摩学习下。 |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed