def __init__(self, root): Frame.__init__(self, root) self.pfr = pifacerelayplus.PiFaceRelayPlus(pifacerelayplus.RELAY) self.pfr.init_board( { 'value': 0, 'direction': 0, 'pullup': 0 }, { 'value': 0, 'direction': 0, # Makes all pins outputs outputs 'pullup': 0 }) root.protocol( "WM_DELETE_WINDOW", self.on_closing ) # This will create a pop-up to confirm ending the program, and # if there is confirmation it will call the on_closing method # to tidy up before closing. self.lightOnImage = PhotoImage(file="icons/light-bulb.png") self.fanImage = PhotoImage(file="icons/ac.png") self.ironImage = PhotoImage(file="icons/iron-soldering.png") self.gpioONImage = PhotoImage(file="icons/switch.png") self.gpioOFFImage = PhotoImage(file="icons/switch-2.png") self.hairdryerImage = PhotoImage(file="icons/hairdryer.png") self.pack(fill=BOTH, expand=True) self.root = root self.root.title(PROGRAM_NAME) self.initUI()
def __init__(self, num): # init GPIO self.__relayNumber = num self.__relays = pifacerelayplus.PiFaceRelayPlus( None, chip_select=1 ) #piface board is configured with address 7, and no expansion board self.period = 1 # time to turn light on self.__duration = 2 # time to turn light off
def __init__(self, root): Frame.__init__(self, root) self.pfr = pifacerelayplus.PiFaceRelayPlus(pifacerelayplus.RELAY) self.pfr.init_board( { 'value': 0, 'direction': 0, 'pullup': 0 }, { 'value': 0, 'direction': 0, # Makes all pins outputs outputs 'pullup': 0 }) root.protocol( "WM_DELETE_WINDOW", self.on_closing ) # This will create a pop-up to confirm ending the program, and # if there is confirmation it will call the on_closing method # to tidy up before closing. # Bench control, Tab 1, variables self.lightOnImage = PhotoImage(file="icons/light-bulb.png") self.fanImage = PhotoImage(file="icons/ac.png") self.ironImage = PhotoImage(file="icons/iron-soldering.png") self.gpioONImage = PhotoImage(file="icons/switch.png") self.gpioOFFImage = PhotoImage(file="icons/switch-2.png") self.hairdryerImage = PhotoImage(file="icons/hairdryer.png") # Camera, Tab 2 variables self.camera = picamera.PiCamera() self.last_photo = None #declaring without defining. self.isVideoRecording = FALSE self.isTakingIntervalPhotos = FALSE self.intervalStillButtonPressed = FALSE self.intervalImageCounter = 0 self.photoInterval = 5 # interval in seconds. self.directory_interval = None self.file_name_interval = None self.intervalCamera = PhotoImage(file="icons/multiple-shots.png") self.videoCamera = PhotoImage(file="icons/video-camera.png") self.add = PhotoImage(file="icons/add.png") self.remove = PhotoImage(file="icons/minus.png") self.stillCamera = PhotoImage(file="icons/photo-camera.png") # Environment, Tab 3 variables self.pi = pigpio.pi() self.sensor = DHT22.sensor(self.pi, DHT_SENSOR_PIN) self.clock = PhotoImage(file="icons/clock.png") self.humidity = PhotoImage(file="icons/humidity.png") self.thermometer = PhotoImage(file="icons/thermometer.png") self.pack(fill=BOTH, expand=True) self.root = root self.root.title(PROGRAM_NAME) self.initUI()
def endfuel(): pfr = pifacerelayplus.PiFaceRelayPlus(pifacerelayplus.RELAY) print('End Fueling') armed = 'Y' fueling = 'N' fueled = 'Y' launch = 'N' abort = 'N' pfr.relays[0].toggle() createconfig(armed, fueling, fueled, launch, abort) return fueled
def launch(): armed, fueling, fueled, launch, abort = readconfig() pfr = pifacerelayplus.PiFaceRelayPlus(pifacerelayplus.RELAY) pfr.relays[0].turn_on() pfr.relays[1].turn_on() sleep(1) pfr.relays[1].toggle() pfr.relays[0].toggle() fueling = 'N' launch = 'Y' abort = 'N' createconfig(armed, fueling, fueled, launch, abort)
def beginfuel(fuel_amount): fuel_amount = int(fuel_amount) pfr = pifacerelayplus.PiFaceRelayPlus(pifacerelayplus.RELAY) print('Begin Fueling') armed = 'Y' fueling = 'Y' fueled = 'N' launch = 'N' abort = 'N' pfr.relays[0].turn_on() sleep(fuel_amount) pfr.relays[0].toggle() createconfig(armed, fueling, fueled, launch, abort)
from time import sleep import pifacerelayplus DELAY = 1.0 # seconds if __name__ == "__main__": pfr = pifacerelayplus.PiFaceRelayPlus(pifacerelayplus.RELAY) while True: pfr.relays[0].toggle() sleep(DELAY)
import pifacerelayplus import time def toggle_leds(pfr): for r in pfr.relays: r.toggle() time.sleep(1) if __name__ == '__main__': # init board with 10 MHz spi speed pfr = pifacerelayplus.PiFaceRelayPlus(pifacerelayplus.RELAY, speed_hz=10000000) while True: toggle_leds(pfr)
from time import sleep import pifacerelayplus DELAY = 1.0 # seconds if __name__ == "__main__": pfr = pifacerelayplus.PiFaceRelayPlus(pifacerelayplus.MOTOR_DC) while True: pfr.motors[0].forward() sleep(2.0) pfr.motors[0].brake() sleep(DELAY) pfr.motors[0].reverse() sleep(2.0) pfr.motors[0].brake() sleep(DELAY) # pfr.motors[0].reverse() # sleep(DELAY) # pfr.motors[1].forward() # sleep(DELAY) # pfr.motors[0].reverse() # sleep(DELAY) # pfr.motors[1].reverse() # sleep(DELAY) # pfr.relays[0].toggle() # sleep(DELAY) # pfr.relays[1].toggle() # sleep(DELAY) # pfr.relays[2].toggle() # sleep(DELAY)
from time import sleep from triangula.input import SixAxis, SixAxisResource import pifacerelayplus #def handler(button): # print "Button {} pressed".format(button) DELAY = 0.001 # seconds if __name__ == "__main__": pfr = pifacerelayplus.PiFaceRelayPlus(pifacerelayplus.MOTOR_STEPPER) with SixAxisResource(bind_defaults=True) as joystick: joystick.register_button_handler(handler, SixAxis.BUTTON_SQUARE) while True: x = joystick.axes[0].corrected_value() y = joystick.axes[1].corrected_value() print(x, y) pfr.motors[0].coast() # sleep(DELAY) pfr.motors[1].brake() sleep(0.11) # pfr.motors[0].forward(10,DELAY) # sleep(DELAY) pfr.motors[1].forward(500, DELAY) sleep(0.1) pfr.motors[1].coast() sleep(0.1) pfr.motors[1].reverse(500, DELAY) sleep(0.1)
import click from flask import current_app, g from flask.cli import with_appcontext import pifacerelayplus relay_board = pifacerelayplus.PiFaceRelayPlus(pifacerelayplus.RELAY) relays = relay_board.relays def get_relay_board(): if "relay_board" not in g: g.relay_board = relays return g.relay_board """Clear existing data and create new tables.""" @click.command("init-relay_board") @with_appcontext def init_relay_board_command(): """Clear existing data and create new tables.""" get_relay_board() click.echo("Initialized the database.") def init_app(app): """Register database functions with the Flask app. This is called by the application factory. """ # app.teardown_appcontext(close_relay_board) app.cli.add_command(init_relay_board_command)
def setRelay(self, num, add): self.relayNumber = num self.relayAddress = add self.pfr = pifacerelayplus.PiFaceRelayPlus(pifacerelayplus.RELAY, self.relayAddress)
def setRelayAddress(self, add): self.relayAddress = add self.pfr = pifacerelayplus.PiFaceRelayPlus(pifacerelayplus.RELAY, self.relayAddress)
def initializeRelays(self): self.pfr = [] self.pfr.append( PFRP.PiFaceRelayPlus() ) self.clearRelays()
def setUp(self): self.pfrp = pifacerelayplus.PiFaceRelayPlus( plus_board=pifacerelayplus.BUTTON)