红绿灯(视频中有小错误,正确代码如下) import RPi.GPIO as GPIO import time pings = 11,12,13,15,16,18 GPIO.setmode(GPIO.BOARD) GPIO.stewarnings(False) GPIO.setup(pings,GPIO.OUT) GPIO.output(pings,False) green = 11 yellow = 13 red = 16 def lukou(): #green GPIO.output(11,True);time.sleep(7) GPIO.output(11,False) #yellow GPIO.output(13,True);time.sleep(0.5) GPIO.output(13,False);time.sleep(0.5) GPIO.output(13, True);time.sleep(0.5) GPIO.output(13, False);time.sleep(0.5) GPIO.output(13, True);time.sleep(0.5) GPIO.output(13, False) #red GPIO.output(16,False);time.sleep(10) if __name__ == '__main__': try: lukou() except KeyboardInterrupt: GPIO.cleanup()