Skip to content

Instantly share code, notes, and snippets.

@Westlad
Created January 4, 2017 09:36
Show Gist options
  • Save Westlad/1f4236317303462a17a9b4b9f1ecdbbd to your computer and use it in GitHub Desktop.
Save Westlad/1f4236317303462a17a9b4b9f1ecdbbd to your computer and use it in GitHub Desktop.
A simple Python script to turn on or off an output for a PiFace Digital board
#!/usr/bin/python
# By Duncan Westland
# Programme to control a heater via command line switches.
# Uses a Raspberry Pi
import sys
import pifacedigitalio
piFace = pifacedigitalio.PiFaceDigital() #creat piface digital object
def printUsage():
print
print "-n to turn on"
print "-f to turn off"
print "-h or --help prints this message"
print
def turnOn():
piFace.output_pins[2].turn_on() #turn OC pin 2 on
def turnOff():
piFace.output_pins[2].turn_off() #turn OC pin 2 off
def main():
if (len(sys.argv)<2):
printUsage()
elif sys.argv[1]=="-n":
print "turning on"
turnOn()
elif sys.argv[1]=="-f":
print "turning off"
turnOff()
else:
printUsage()
sys.exit(2)
if __name__=="__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment