def speaker_gpio(gpio_pin): if gpio_pin == 0: print('Using DummyGPIO') class DummyGPIO: def set(self): pass def reset(self): pass yield DummyGPIO() print('Allocing pin {gpio_pin}.format(gpio_pin)', sys.stderr) gpio = Controller.alloc_pin(gpio_pin, OUTPUT) try: yield gpio finally: print('Deallocing pin {}'.format(gpio_pin), sys.stderr) gpio.reset() Controller.dealloc_pin(gpio_pin)
def destroy(self): self.pin_controller.set() Controller.dealloc_pin(self.PIN) reactor.stop()
self.delayMicroseconds(1) # commands need > 37us to settle def message(self, text): """ Send string to LCD. Newline wraps to second line""" for char in text: if char == '\n': self.write4bits(0xC0) # next line else: self.write4bits(ord(char), True) def loop(): lcd = CharLCD() while True: lcd.clear() sleep(2) lcd.message(" TEST MODE !\n Whatup?") sleep(10) return lcd if __name__ == '__main__': try: lcd = loop() reactor.run() except: for pin in Controller.available_pins: Controller.dealloc_pin(pin) reactor.stop()