Beispiel #1
0
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)
Beispiel #2
0
 def all_colors(stripe):
     Colorizer.logger.debug("running...")
     from control import get_stop_flag
     while not get_stop_flag():
         new_strip = Colorizer(stripe)
         for color in new_strip.colors:
             if isinstance(color, str) and not get_stop_flag():
                 new_strip.set_color(color)
                 yield new_strip
             if get_stop_flag():
                 break
     clear(stripe)
Beispiel #3
0
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)
Beispiel #4
0
def run_clock6(strip):
    LOGGER.debug("running...")
    from control import get_stop_flag
    while not get_stop_flag():
        try:
            hour_value, minute_value = _get_pointer(strip)[:2]
            # arc mode
            intensity = 100
            for i in range(strip.numPixels()):
                # calculates a faded arc from low to maximum brightness
                h = _get_color_value(i, hour_value, intensity=intensity)
                m = _get_color_value(i, minute_value, intensity=intensity)
                red, green, blue = 0, m, h
                color = Color(red, green, blue)
                strip.setPixelColor(i % 24, color)
            strip.show()
            time.sleep(0.1)

        except KeyboardInterrupt:
            LOGGER.warn("KeyboardInterrupt.")
            exit()

        except Exception as e:
            LOGGER.error(f"Any error occurs: {e}")
            exit()

    clear(strip)
Beispiel #5
0
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)
Beispiel #6
0
def run_stroboscope(stripe):
    from control import get_stop_flag
    stripe.setBrightness(255)
    Colorizer.logger.debug("running...")
    while not get_stop_flag():
        Colorizer(stripe, 1).start()
        t = uniform(0.005, 0.05)
        if get_stop_flag():
            break
        time.sleep(t)
        Colorizer(stripe, 0).start()
        t = uniform(0.5, 3)
        if get_stop_flag():
            break
        time.sleep(t)
    clear(stripe)
Beispiel #7
0
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)
Beispiel #8
0
def run_candles(strip):
    LOGGER.debug("running...")
    from control import get_stop_flag
    while not get_stop_flag():
        try:
            candle(strip, strip.numPixels())

        except KeyboardInterrupt:
            LOGGER.warn("KeyboardInterrupt")
            exit()

        except Exception as e:
            LOGGER.error(f"Any error occurs: {e}")
            exit()
    clear(strip)
Beispiel #9
0
def run_advent(stripe):
    LOGGER.debug("running...")
    from control import get_stop_flag
    i = 1

    while not get_stop_flag():
        year = datetime.datetime.now().year
        if __is_advent_period(year):
            __advent_cycle(stripe)
        else:
            while i > 0:
                LOGGER.warning(f"Wrong period to show xmas/advent animation, "
                               f"it\'s {time.strftime('%A, %d.%B %Y')}!")
                i -= 1
            theater_chase(stripe, Color(ZERO[0], ZERO[1], ZERO[2]))
    clear(stripe)
Beispiel #10
0
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)
Beispiel #11
0
def run_clock2(strip):
    LOGGER.debug("running...")
    from control import get_stop_flag
    while not get_stop_flag():
        try:
            hour, minute, next_minute = _get_pointer(strip)
            while not minute == next_minute:
                # 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(0.2)
                minute = _get_pointer(strip)[1]
            _wipe_second(strip, COLOR_MINUTE_DIMMED, minute - 1, backward=True)
            clear(strip)
        except KeyboardInterrupt:
            print()
            LOGGER.warn("KeyboardInterrupt.")
            exit()
        except Exception as e:
            LOGGER.error(f"Any error occurs: {e}")
            exit()
    clear(strip)
Beispiel #12
0
 def run_color(stripe, color_key: str):
     Colorizer.logger.debug(f"running '{color_key.title()}'...")
     from control import get_stop_flag
     while not get_stop_flag():
         Colorizer(stripe, color_key).start()
     clear(stripe)