|
利用DIDO module的输出状态指示LED实现跑马灯演示程序。通过S0和S1按键输入切换不同的显示模式
因为继电器0和继电器1 并联到输出的0和1.。程序演示时需先将JP5,JP6断开,以免程序演示时继电器不停切换发出噪音。
vim simple_led.py 新建程序文件
输入以下内容:
#!/usr/bin/python3
from time import sleep
import pifacedigitalio
DELAY = 0.2 #seconds
def led_fun1():
for i in(0,1,2,3,4,5,6,7):
pifacedigital.output_port.value = 0x01<<i
sleep(DELAY)
def led_fun2():
pifacedigital.output_port.value = 0
for i in(0,1,2,3,4,5,6,7):
pifacedigital.output_port.value += 0x01<<i
sleep(DELAY)
for i in(7,6,5,4,3,2,1,0):
pifacedigital.output_port.value -= 0x01<<i
sleep(DELAY)
def led_off():
pifacedigital.output_port.value=0
def key_sacn():
returnpifacedigital.input_port.value
if __name__ == "__main__":
pifacedigital = pifacedigitalio.PiFaceDigital()
while True:
key =key_sacn()
if(key==1):
led_fun1()
elif(key==2):
led_fun2()
else:
led_off()
chmod a+x simple_led.py添加可执行权限
./simple_led.py 运行示例程序 |
|