Skip to content

Instantly share code, notes, and snippets.

@adammelancon
Last active December 21, 2015 01:59
Show Gist options
  • Save adammelancon/6231840 to your computer and use it in GitHub Desktop.
Save adammelancon/6231840 to your computer and use it in GitHub Desktop.
A small class I wrote to easily turn on and off the relay on a PiFace for the Raspberry Pi.
import time
import piface.pfio as pfio
pfio.init()
# A class to controll the relay
class Bpress:
def relayon(self):
pfio.digital_write(1,1)
print "Turning on relay!"
while True:
if pfio.digital_read(0) == 0:
return
def relayoff(self):
pfio.digital_write(1,0)
print "Turning off relay!"
while True:
if pfio.digital_read(1) == 0:
return
piface = Bpress()
# Relay Test
piface.relayon()
time.sleep(3)
piface.relayoff()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment