def run_theater(strip): LOGGER.debug("running...") from control import get_stop_flag while not get_stop_flag(): try: set_brightness_depending_on_daytime(strip) color_wipe_full(strip, Color(127, 0, 0)) # Red wipe if not get_stop_flag(): color_wipe_full(strip, Color(0, 127, 0)) # Green wipe if not get_stop_flag(): color_wipe_full(strip, Color(0, 0, 127)) # Blue wipe if not get_stop_flag(): color_wipe_full(strip, Color(127, 127, 127)) # White wipe if not get_stop_flag(): theater_chase(strip, Color(127, 127, 127)) # White theater chase if not get_stop_flag(): theater_chase(strip, Color(0, 0, 127)) # Blue theater chase if not get_stop_flag(): theater_chase(strip, Color(0, 127, 0)) # Green theater chase if not get_stop_flag(): theater_chase(strip, Color(127, 0, 0)) # Red theater chase except KeyboardInterrupt: LOGGER.warn("KeyboardInterrupt") exit() except Exception as e: LOGGER.error(f"Any error occurs: {e}") exit() clear(strip)
def run_rainbow(strip): LOGGER.debug("running...") from control import get_stop_flag while not get_stop_flag(): try: set_brightness_depending_on_daytime(strip) for j in range(256 * 5): if not get_stop_flag(): for i in range(strip.numPixels()): if not get_stop_flag(): strip.setPixelColor( i, wheel((int(i * 256 / strip.numPixels()) + j) & 255)) if not get_stop_flag(): strip.show() time.sleep(.02) except KeyboardInterrupt: LOGGER.warn("KeyboardInterrupt") exit() except Exception as e: LOGGER.error(f"Any error occurs: {e}") exit() clear(strip)
def run_demo2(stripe): for c in Colorizer.all_colors(stripe): for i in range(set_brightness_depending_on_daytime(stripe)[1]): c.start(brightness=i) time.sleep(uniform(0.001, 0.05)) for i in range(set_brightness_depending_on_daytime(stripe)[1]): b = set_brightness_depending_on_daytime(stripe)[1] - i c.start(brightness=b) time.sleep(uniform(0.001, 0.05))
def run_clock3(stripe): LOGGER.debug("running...") from control import get_stop_flag while not get_stop_flag(): try: now = set_brightness_depending_on_daytime(stripe)[0] led_for_hour = int(int(now.hour) % 12 * 2) led_for_minute = int(now.minute // 2.5) leds_per_2500ms = int(round(now.second / 2.5)) _dial(stripe) _seconds(leds_per_2500ms, stripe) _minute(led_for_minute, led_for_hour, stripe) _hour(led_for_hour, stripe) stripe.show() time.sleep(0.2) if leds_per_2500ms == stripe.numPixels(): time.sleep(1.3) clear(stripe) except KeyboardInterrupt: LOGGER.warn("KeyboardInterrupt.") exit() except Exception as e: LOGGER.error(f"Any error occurs: {e}") exit() clear(stripe)
def _get_pointer(strip): now = set_brightness_depending_on_daytime(strip)[0] second_value = int(now.second / 2.5) minute_value = int(now.minute / 2.5) hour_value = int(now.hour) hour_value = hour_value % 12 * 2 hour_value = int((hour_value * 24 + minute_value) / 24) return hour_value, minute_value, second_value
def run_clock5(strip): LOGGER.debug("running...") from control import get_stop_flag p_left = 0 p_right = len(pendulum) - 1 while not get_stop_flag(): try: clear(strip) now = set_brightness_depending_on_daytime(strip)[0] hour = int(int(now.hour) % 12 * 2) minute = int(now.minute // 2.5) # pendulum of second for i in range(len(pendulum)): strip.setPixelColor(pendulum[i], COLOR_SECOND_DIMMED) if p_left >= len(pendulum) - 1: if p_right <= 0: p_right = len(pendulum) - 1 p_left = 0 else: strip.setPixelColor(pendulum[p_right], COLOR_SECOND) p_right -= 1 else: strip.setPixelColor(pendulum[p_left], COLOR_SECOND) p_left += 1 # pointer # hour if 12 < minute <= 23: strip.setPixelColor(hour, COLOR_HOUR) strip.setPixelColor(hour + 1, COLOR_HOUR_DIMMED) else: strip.setPixelColor(hour, COLOR_HOUR) # minute if minute == hour: if 12 < minute < strip.numPixels(): if hour <= 23: strip.setPixelColor(hour + 1, COLOR_HOUR) strip.setPixelColor(minute, COLOR_MINUTE) else: strip.setPixelColor(0, COLOR_HOUR) strip.setPixelColor(minute - 1, COLOR_MINUTE) else: strip.setPixelColor(minute + 1, COLOR_MINUTE) else: strip.setPixelColor(minute, COLOR_MINUTE) strip.show() time.sleep(wait_ms) except KeyboardInterrupt: print() LOGGER.warn("KeyboardInterrupt.") exit() except Exception as e: LOGGER.error(f"Any error occurs: {e}") exit() clear(strip)
def start(self, brightness=None): try: if self.__color is None: raise Exception('Start without set color!') else: if brightness is None: set_brightness_depending_on_daytime(self.__strip) else: self.__strip.setBrightness(brightness) for i in range(self.__strip.numPixels()): self.__strip.setPixelColor(i, self.__get_color(self.__color)) self.__strip.show() except KeyboardInterrupt: self.__log.warn("KeyboardInterrupt") exit() except Exception as e: self.__log.error(f"An error occurs: {e}") exit()
def run_clock1(strip): LOGGER.debug("running...") from control import get_stop_flag while not get_stop_flag(): # noinspection PyBroadException try: now = set_brightness_depending_on_daytime(strip)[0] hour = int(int(now.hour) % 12 * 2) minute = int(now.minute // 2.5) second = int(now.second // 2.5) for i in range(0, strip.numPixels(), 1): # hour strip.setPixelColor(hour, COLOR_HOUR) # minute if minute == hour: if 12 < minute < strip.numPixels(): if hour <= 23: strip.setPixelColor(hour + 1, COLOR_HOUR) strip.setPixelColor(minute, COLOR_MINUTE) else: strip.setPixelColor(0, COLOR_HOUR) strip.setPixelColor(minute - 1, COLOR_MINUTE) else: strip.setPixelColor(minute + 1, COLOR_MINUTE) else: strip.setPixelColor(minute, COLOR_MINUTE) # second if i == second: strip.setPixelColor(i, COLOR_SECOND) else: strip.setPixelColor(i, Color(0, 0, 0)) strip.show() time.sleep(0.1) except KeyboardInterrupt: print() LOGGER.warn("KeyboardInterrupt.") exit() except Exception as e: LOGGER.error(f"Any error occurs: {e}") exit() clear(strip)
def _get_pointer(strip): now = set_brightness_depending_on_daytime(strip)[0] hour = int(int(now.hour) % 12 * 2) minute = int(now.minute // 2.5) next_minute = minute + 1 if minute <= 22 else 0 return hour, minute, next_minute