티스토리 뷰
2.11. 라즈베리파이 신호등
#신호등 예제1
from gpiozero import TrafficLights from time import sleep lights = TrafficLights(2, 3, 4) lights.green.on() while True: sleep(10) lights.green.off() lights.amber.on() sleep(1) lights.amber.off() lights.red.on() sleep(10) lights.amber.on() sleep(1) lights.green.on() lights.amber.off() lights.red.off()
#신호등 예제2
from gpiozero import TrafficLights from time import sleep from signal import pause lights = TrafficLights(2, 3, 4) def traffic_light_sequence(): while True: yield (0, 0, 1) # green sleep(10) yield (0, 1, 0) # amber sleep(1) yield (1, 0, 0) # red sleep(10) yield (1, 1, 0) # red+amber sleep(1) lights.source = traffic_light_sequence() pause()
#신호등 예제3
from gpiozero import LED from time import sleep red = LED(2) amber = LED(3) green = LED(4) green.on() amber.off() red.off() while True: sleep(10) green.off() amber.on() sleep(1) amber.off() red.on() sleep(10) amber.on() sleep(1) green.on() amber.off() red.off()
'프로그래밍 > 라즈베리파이 & Qt' 카테고리의 다른 글
2.13. 라즈베리파이 반응 게임 (2) | 2018.08.22 |
---|---|
2.12. 라즈베리파이 푸시 버튼 스톱 모션 (0) | 2018.08.22 |
2.10. 라즈베리파이 LED 막대 그래프 (0) | 2018.08.22 |
2.9. 라즈베리파이 LEDBoard (0) | 2018.08.21 |
2.8. 라즈베리파이 셧다운 버튼 (0) | 2018.08.21 |
댓글