Created
January 4, 2017 09:36
-
-
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
This file contains 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 | |
# 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 "-n to turn on" | |
print "-f to turn off" | |
print "-h or --help prints this message" | |
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