def setupButtons(): global buttonLeft, buttonMiddle, buttonRight buttonLeft = Button(BUTTON_LEFT_GPIO_PIN) buttonMiddle = Button(BUTTON_MIDDLE_GPIO_PIN) buttonRight = Button(BUTTON_RIGHT_GPIO_PIN) buttonLeft.when_pressed = leftPressed buttonMiddle.when_pressed = middlePressed buttonRight.when_pressed = rightPressed buttonLeft.when_held = leftHeld buttonMiddle.when_held = middleHeld buttonRight.when_held = rightHeld buttonLeft.when_released = leftReleased buttonMiddle.when_released = middleReleased buttonRight.when_released = rightReleased buttonLeft.hold_time = 1 buttonMiddle.hold_time = 1 buttonRight.hold_time = 1 buttonLeft.hold_repeat = True buttonMiddle.hold_repeat = True buttonRight.hold_repeat = True
def add_button(self, pin, name, pull_up=True, bounce_time=None, hold_time=None, hold_repeat=None): if self._button_map.has_key(pin): return # TODO: Reference http://stackoverflow.com/a/21986301/1846662 for a better way to call Button() if bounce_time > 0: button = Button(pin, pull_up, bounce_time) else: button = Button(pin, pull_up) if hold_time > 0: button.hold_time = hold_time if type(hold_repeat) is bool: button.hold_repeat = hold_repeat button.when_activated = self._handle_pressed button.when_deactivated = self._handle_released button.when_held = self._handle_held self._button_map[pin] = NamedButton(name, button, pin)