Last active
September 18, 2015 17:53
-
-
Save xerp/e18024cd9a6c9fe03679 to your computer and use it in GitHub Desktop.
Revisions
-
xerp revised this gist
Sep 18, 2015 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ import RPi.GPIO as pins from components import Semaphore s = Semaphore(pins,red_pin,yellow_pin,green_pin) s.start(10,2,10) -
xerp renamed this gist
Sep 18, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
xerp revised this gist
Sep 18, 2015 . No changes.There are no files selected for viewing
-
xerp revised this gist
Sep 18, 2015 . No changes.There are no files selected for viewing
-
xerp revised this gist
Sep 18, 2015 . No changes.There are no files selected for viewing
-
xerp renamed this gist
Sep 18, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
xerp created this gist
Sep 18, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ import RPi.GPIO as GPIO import time class LED: def __init__(self,gpio,pin): gpio.setmode(GPIO.BCM) gpio.cleanup(pin) gpio.setup(pin,GPIO.OUT) self.__gpio = gpio self.__pin = pin def on(self): self.__gpio.output(self.__pin,True) def off(self): self.__gpio.output(self.__pin,False) class Semaphore: def __init__(self,gpio,red_pin,yellow_pin,green_pin): gpio.setmode(GPIO.BCM) self._led_red = LED(gpio,red_pin) self._led_yellow = LED(gpio,yellow_pin) self._led_green = LED(gpio,green_pin) def reset(self): self._led_red.off() self._led_yellow.off() self._led_green.off() def __led(self,color,led_time): led = getattr(self,'_led_{0}'.format(color)) if isinstance(led,LED): led.on() time.sleep(led_time) led.off() def start(self,red_time,yellow_time,green_time): while True: self.__led('red',red_time) self.__led('yellow',yellow_time) self.__led('green',green_time)