def _start_heartbeat(self): """ Start the heartbeat animation. """ if not self.heartbeat: self.heartbeat = self._run_heartbeat_loop() call_soon(self.heartbeat)
def start(self, animation, delay=0): """ Start a new animation. :param Animation animation: The animation to run :param int delay: The delay in milliseconds before animating """ self.stop() self.animation = animation self.animation._running = True self.runner = self._run_animation(animation, delay, self.current) call_soon(self.runner)
def on_connected_right(self, device): """ Invoked when a new device is connected to the right port by the user. :param Device device: The device which was connected """ self.right = device # If this is a sensor being connected start reading values from it if device.is_sensor(): self.right_read = read_sensor_input(device, self.on_right_value_changed) call_soon(self.right_read) if device.is_actuator(): device.set_value(self.left_value) self._update_display()
def on_enter(self): hub.sound.volume(10) # Fade in the initial image current_program = self.get_current_program() current_image = current_program.get_image() hub.display.show(current_image, fade=2) # Start LED fading in animation self.led_fade = call_soon(led_fade_to(BLUE, 100, 1))
def on_right_button_down(self): """ Invoked when the user presses down the left button. This triggers the adjust coroutine which increase the values of actuators connected to either of the two ports (if any). If the user has pressed down both left and right buttons at the same time, then the values are reset in stead of running the coroutine. """ if hub.button.left.is_pressed(): # Both buttons are pressed down self._reset_values() return def _predicate(): return (hub.button.right.is_pressed() and not hub.button.left.is_pressed()) self._update_display() self.adjust = self._adjust_actuator_value(_predicate, 10) call_soon(self.adjust)
def on_resume(self): current_program = self.get_current_program() current_image = current_program.get_image() animation = shift_in_from_bottom(current_image) hub.sound.play(Sounds.PROGRAM_STOP, 16000) hub.display.show(animation, delay=44) # Stop LED fading in and out animation if self.led_fade_in_out: cancel(self.led_fade_in_out) self.led_fade_in_out = None # Start LED fade in animation self.led_fade = call_soon(led_fade_to(BLUE, 100, 1))
def on_pause(self): current_program = self.get_current_program() current_image = current_program.get_image() animation = shift_out_to_bottom(current_image) hub.sound.play(Sounds.PROGRAM_START, 16000) hub.display.show(animation, delay=44) # Stop LED fade in animation if self.led_fade: cancel(self.led_fade) self.led_fade = None # Start LED fading in and out animation self.led_fade_in_out = call_soon(led_fade_in_out())