def activated(): gpio_red = gpio.GPIO(GPIO.gpio_id("GPIO-B"), gpio.DIRECTION_OUTPUT) gpio_green = gpio.GPIO(GPIO.gpio_id("GPIO-C"), gpio.DIRECTION_OUTPUT) gpio_blue = gpio.GPIO(GPIO.gpio_id("GPIO-D"), gpio.DIRECTION_OUTPUT) with gpio.request_gpios((gpio_red, gpio_green, gpio_blue)): gpio_green.set_low() gpio_blue.set_low() gpio_blue.set_high()
def __init__(self, xioNumber): ''' :param onFor: ms to keep light on :param onFor: ms to keep light off ''' self._xio = GPIO(self.xioToDev(xioNumber), DIRECTION_OUTPUT) self._xio.open() self._xio.set_high() #start off in high (off) state self._blinkPattern = [0, .1] threading.Thread.__init__(self)
def activate_defences(): gpio_red = gpio.GPIO(GPIO.gpio_id("GPIO-B"), gpio.DIRECTION_OUTPUT) gpio_green = gpio.GPIO(GPIO.gpio_id("GPIO-C"), gpio.DIRECTION_OUTPUT) gpio_blue = gpio.GPIO(GPIO.gpio_id("GPIO-D"), gpio.DIRECTION_OUTPUT) counter = 10 with gpio.request_gpios((gpio_red, gpio_green, gpio_blue)): gpio_green.set_low() gpio_blue.set_low() while counter > 0: gpio_red.set_high() sleep(0.5) gpio_red.set_low() sleep(0.5) counter = counter - 1
class BlinkThread(threading.Thread): BASE_XIO = 408 def setBlinkPattern(self, blinkPattern): self._blinkPattern = blinkPattern def xioToDev(self, xio): return self.BASE_XIO + xio _stopped = False def __init__(self, xioNumber): ''' :param onFor: ms to keep light on :param onFor: ms to keep light off ''' self._xio = GPIO(self.xioToDev(xioNumber), DIRECTION_OUTPUT) self._xio.open() self._xio.set_high() #start off in high (off) state self._blinkPattern = [0, .1] threading.Thread.__init__(self) def stop(self): self._stopped = True def run(self): while True: state = True for blink in self._blinkPattern: if self._stopped: #detect stop here too break if state: self._xio.set_low() #low is on else: self._xio.set_high() # high is off state = not state #toggle time.sleep(blink)
def sensor_activated(): gpio_in = gpio.GPIO(GPIO.gpio_id("GPIO-A"), gpio.DIRECTION_INPUT) with gpio.request_gpios(gpio_in): in_val = gpio_in.is_high() return in_val
from time import sleep from libsoc import gpio from libsoc import GPIO # GPIO.set_debug(True) gpio_out = gpio.GPIO(GPIO.gpio_id("GPIO-B"), gpio.DIRECTION_OUTPUT) with gpio.request_gpios(gpio_out): while True: gpio_out.set_high() sleep(1) gpio_out.set_low() sleep(1)