from gpiozero import Button, TrafficLights, Buzzer from time import sleep lights = TrafficLights(25, 8, 7) button = Button(21) buzzer= Buzzer(15) while True: button.wait_for_press() lights.green.on() sleep(1) lights.amber.on() sleep(1) lights.red.on() sleep(1) lights.off() buzzer.beep()
from gpiozero import Button, TrafficLights, Buzzer button = Button(3) tr1 = TrafficLights(25, 8, 7) tr2 = TrafficLights(16, 20, 21) buzzer = Buzzer(15) while True: tr2.on() buzzer.off() button.wait_for_press() tr2.off() #buzzer.on(245) button.wait_for_release()
cross1 = TrafficLights(2, 3, 4) cross2 = TrafficLights(18, 15, 14) btn = Button(5) def pressed(): print("Don't push the button!") btn.when_pressed = pressed while True: tl1.red.on() sleep(1) tl1.amber.on() btn.press() # for demo purposes sleep(1) tl1.off() tl1.green.on() sleep(3) tl1.off() tl1.amber.on() sleep(1) tl1.off() while True: tl1.value = (1, 0, 0) sleep(1) tl1.value = (1, 1, 0) sleep(1) tl1.value = (0, 0, 1) sleep(3) tl1.value = (0, 1, 0)
lights.amber.on() time.sleep(cycle_time) # Green lights.red.off() lights.amber.off() lights.green.on() time.sleep(cycle_time) # Amber lights.green.off() lights.amber.on() time.sleep(cycle_time) # Red lights.amber.off() lights.red.on() time.sleep(cycle_time) lights = TrafficLights(17, 27, 22) while True: british_lights_cycle(lights, 0.75) lights.off() time.sleep(0.75) lights.off() print "done!"
from gpiozero import Button, TrafficLights from time import sleep Car_red = 18 Car_amber = 17 Car_green = 27 Pd_red = 12 Pd_green = 6 button_pin = 13 Car = TrafficLights(Car_red, Car_amber, Car_green) Ped = TrafficLights(Pd_red, 14, Pd_green) button = Button(button_pin) Car.off() Ped.off() try: def change(): Car.green.off() Car.amber.on() print("Car yellow, Pedestrian red") sleep(1) Car.amber.off() Car.red.on() Ped.red.off() Ped.green.on() print("Car red, Pedestrian green") sleep(5) Car.red.off()
traffic_light1.green.on() traffic_light2.red.off()# go signal for south bound traffic traffic_light2.amber.off() traffic_light2.green.on() traffic_light3.red.on() # stop signal for valley 1 traffic traffic_light3.amber.off() traffic_light3.green.off() sleep(2) #standby for 2 seconds until the cycle begins traffic_light1.red.off() #all warning LED light is on traffic_light1.amber.on() traffic_light1.green.off() traffic_light2.red.off() traffic_light2.amber.on() traffic_light2.green.off() traffic_light3.red.off() traffic_light3.amber.on() traffic_light3.green.off() sleep(1)# standby for 1 sec break #if the distance value is less than 100cm .. then break the loop pause() except KeyboardInterrupt: #ctrl C to turn off the LED and sensor traffic_light1.off() traffic_light2.off() traffic_light3.off() print('Device off......')