当前位置:网站首页>Raspberry pie tap switch button to use

Raspberry pie tap switch button to use

2022-07-06 11:54:00 Forgotten world

Please add group for problem consultation and project source code download :

Group name :IT Project communication group

Group number :245022761

 

 

2、 Use raspberry pie to design a simple key control LED Light on system . Read the external digital signal through the raspberry pie controller , Use three buttons to control three colors LED The lamp , When a key is pressed, the corresponding LED The light will light up , After the key is released, the corresponding LED The light goes out . Press one of the three keys , You can see the corresponding one LED The light will light up ; When pressing two buttons at the same time , Two corresponding LED The light will come on ; When you press three keys at the same time, there are three LED The lights are on at the same time . Complete the hardware connection circuit design of the control system , Draw the system hardware principle block diagram and program flow chart , Programming , The system has passed the joint commissioning and has been summarized and analyzed .

  1. import RPi.GPIO
    import time
    yellow=0
    red=5
    green=6
    button1=13
    button2=19
    button3=26
    RPi.GPIO.setmode(RPi.GPIO.BCM)
    RPi.GPIO.setup(red,RPi.GPIO.OUT)
    RPi.GPIO.setup(green,RPi.GPIO.OUT)
    RPi.GPIO.setup(yellow,RPi.GPIO.OUT)
    RPi.GPIO.setup(button1, RPi.GPIO.IN, pull_up_down=RPi.GPIO.PUD_UP)
    RPi.GPIO.setup(button2, RPi.GPIO.IN, pull_up_down=RPi.GPIO.PUD_UP)
    RPi.GPIO.setup(button3, RPi.GPIO.IN, pull_up_down=RPi.GPIO.PUD_UP)
    try:
        RPi.GPIO.output(red,1)
        RPi.GPIO.output(green,1)
        RPi.GPIO.output(yellow,1)
       
        while True:
                time.sleep(0.06)
                if RPi.GPIO.input(button1) == 0:
                    RPi.GPIO.output(red,1)
                else:
                    RPi.GPIO.output(red,0)
    
                if RPi.GPIO.input(button2) == 0:
                    RPi.GPIO.output(green,1)
                else:
                     RPi.GPIO.output(green,0)
    
                if RPi.GPIO.input(button3) == 0:
                     RPi.GPIO.output(yellow, 1)
                else:
                      RPi.GPIO.output(yellow, 0)
    
    
    
    except KeyboardInterrupt:
        pass
    

     

原网站

版权声明
本文为[Forgotten world]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060913166251.html