I'm looking to build an automation application using the Rasbery Pi + Piface board, using Python.
I've got as far as being able to switch the LEDs on and off from a command line Python script, however every time the script is called it re-sets the board when the init command is given. So for example if I call it once to turn LED1 on, when I call it again to turn LED2 on it turns LED1 off when the init is issued, but you have to issue the init before you can control things. Is there any way to call init without causing a Piface reset? I want to be able to turn specific things on and off without affecting other things.
Here's the test script - I'm sure there are far better ways to do this but it does as a starting point. This is the first time I've ever looked at Python, I normally work in Perl. It's called as for example: ./test2 on2
#!/usr/bin/env python
import time
import piface.pfio
import sys # import command line arguments
piface.pfio.init()
led1 = piface.pfio.LED(1)
led2 = piface.pfio.LED(2)
led3 = piface.pfio.LED(3)
led4 = piface.pfio.LED(4)
led5 = piface.pfio.LED(5)
if str(sys.argv[1]) == "on1":
led1.turn_on()
elif str(sys.argv[1]) == "on2":
led2.turn_on()
elif str(sys.argv[1]) == "on3":
led3.turn_on()
elif str(sys.argv[1]) == "on4":
led4.turn_on()
elif str(sys.argv[1]) == "on5":
led5.turn_on()
elif str(sys.argv[1]) == "off1":
led1.turn_off()
elif str(sys.argv[1]) == "off2":
led2.turn_off()
elif str(sys.argv[1]) == "off3":
led3.turn_off()
elif str(sys.argv[1]) == "off4":
led4.turn_off()
elif str(sys.argv[1]) == "off5":
led5.turn_off()
else:
print "No valid input specified\n"
print 'Number of arguments:', len(sys.argv), 'arguments.'
piface.pfio.init(False)
to not initialize the ports. Though you'd need a script to run it without the parameter on boot.