Instantly share code, notes, and snippets.

Embed
What would you like to do?
Outlet driver
#!/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