Created
May 19, 2015 07:08
-
-
Save hugokernel/24d50a4c88932fe008e9 to your computer and use it in GitHub Desktop.
Outlet driver
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 characters
#!/usr/bin/python | |
import RPi.GPIO as GPIO | |
from time import sleep | |
class Power_Outlet: | |
OUTPUT0 = 12 | |
OUTPUT1 = 11 | |
OUTPUT2 = 13 | |
STATUS = 15 | |
OUTPUTS = ( OUTPUT0, OUTPUT1, OUTPUT2, STATUS ) | |
OFFS = ( OUTPUT0, OUTPUT1, OUTPUT2 ) | |
DELAY = 0.4 | |
def __init__(self): | |
GPIO.setmode(GPIO.BOARD) | |
GPIO.setwarnings(False) | |
for output in self.OUTPUTS: | |
GPIO.setup(output, GPIO.OUT) | |
self.low() | |
def low(self): | |
for output in self.OUTPUTS: | |
GPIO.output(output, False) | |
def get(self, index): | |
'''Get state | |
''' | |
return GPIO.input(self.OFFS[index]) | |
def on(self, index): | |
GPIO.output(self.OFFS[index], True) | |
GPIO.output(self.STATUS, True) | |
sleep(self.DELAY) | |
self.low() | |
def off(self, index): | |
GPIO.output(self.OFFS[index], True) | |
GPIO.output(self.STATUS, False) | |
sleep(self.DELAY) | |
self.low() | |
if __name__ == '__main__': | |
po = Power_Outlet() | |
for i in range(3): | |
print "Power on switch %i" % i | |
po.on(i) | |
#sleep(1) | |
print "Power off switch %i" % i | |
po.off(i) | |
print("Done !") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment