树莓派点亮小灯泡
Posted wjw1014
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了树莓派点亮小灯泡相关的知识,希望对你有一定的参考价值。
import serial
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(23, GPIO.OUT)
GPIO.setup(24, GPIO.OUT)
GPIO.setup(25, GPIO.OUT)
GPIO.output(23, GPIO.LOW)
GPIO.output(24, GPIO.LOW)
GPIO.output(25, GPIO.LOW)
ser = serial.Serial("/dev/ttyUSB0",9600)
ser.flushInput()
# ser.write("play,001,$")
def main():
while True:
count = ser.inWaiting()
if count !=0:
print(count)
recv = int.from_bytes(ser.read(count), byteorder='big', signed=False)
print(recv)
print(type(recv))
if(recv == 2):
GPIO.output(23, GPIO.HIGH)
GPIO.output(24, GPIO.LOW)
GPIO.output(25, GPIO.LOW)
print("hong deng")
if(recv == 3):
GPIO.output(23, GPIO.LOW)
GPIO.output(24, GPIO.LOW)
GPIO.output(25, GPIO.HIGH)
print("lv deng")
if(recv == 4):
GPIO.output(23, GPIO.LOW)
GPIO.output(24, GPIO.HIGH)
GPIO.output(25, GPIO.LOW)
print("lan deng")
ser.flushInput()
time.sleep(0.1)
if __name__ == '__main__':
main()
以上是关于树莓派点亮小灯泡的主要内容,如果未能解决你的问题,请参考以下文章