Ejemplo n.º 1
0
            FPS = max(MIN_FPS, min(FPS + MOVE, MAX_FPS))
            SPEED = 1.0 / FPS
            CRYSTAL_COMET.speed = SPEED
            #RAINBOW.speed = SPEED
            #CP_RAINBOW.speed = SPEED
            print("crystal speed = ", SPEED)
        else:
            BRIGHTNESS = max(MIN_BRIGHTNESS, min(BRIGHTNESS + MOVE,
                                                 MAX_BRIGHTNESS))
            LEVEL = BRIGHTNESS * 0.1
            if LEVEL > 2:
                LEVEL = 2
            cp.pixels.brightness = LEVEL/2
            PIXEL_MAP_RINGS.brightness = LEVEL/2
            PIXEL_MAP_CRYSTALS.brightness = LEVEL
            print("ring brightness = ", LEVEL/2, "crystal brightness = ", LEVEL)
        LAST_POSITION = POSITION
    if not BUTTON_VALUE and BUTTON_STATE is None:
        BUTTON_STATE = "pressed"
    if BUTTON_VALUE and BUTTON_STATE == "pressed":
        print("Button pressed.")
        if MODE == 1:
            MODE = 2
        else:
            MODE = 1
        BUTTON_STATE = None
    if MODE == 1:
        ANIMATIONS.animate()
    else:
        DARK.animate()
Ejemplo n.º 2
0
# Update to match the pin connected to your NeoPixels
pixel_pin = board.A1
# Update to match the number of NeoPixels you have connected
pixel_num = 64
heart_mask = [
    1, 2, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
    24, 25, 26, 27, 28, 29, 30, 31, 33, 34, 35, 36, 37, 38, 42, 43, 44, 45, 51,
    52
]

unheart_mask = [
    0, 3, 4, 7, 32, 39, 40, 41, 46, 47, 48, 49, 50, 53, 54, 55, 56, 57, 58, 59,
    60, 61, 62, 63
]

pixels = neopixel.NeoPixel(pixel_pin,
                           pixel_num,
                           brightness=0.9,
                           auto_write=False)

animations = AnimationSequence(
    Sparkle(pixels, speed=0.05, color=JADE, num_sparkles=1, mask=unheart_mask),
    Sparkle(pixels, speed=0.05, color=AQUA, num_sparkles=1),
    Sparkle(pixels, speed=0.05, color=PINK, num_sparkles=1, mask=heart_mask),
    advance_interval=5,
    auto_clear=False,
)

while True:
    animations.animate()
# SPDX-FileCopyrightText: 2021 Rose Hooper
# SPDX-License-Identifier: MIT

import board
from adafruit_led_animation.animation.sparkle import Sparkle
from adafruit_led_animation.color import PURPLE
from adafruit_led_animation.sequence import AnimationSequence

from adafruit_is31fl3741.adafruit_ledglasses import MUST_BUFFER, LED_Glasses
from adafruit_is31fl3741.led_glasses_animation import LED_Glasses_Animation

glasses = LED_Glasses(board.I2C(), allocate=MUST_BUFFER)
glasses.set_led_scaling(255)
glasses.global_current = 0xFE
glasses.enable = True

pixels = LED_Glasses_Animation(glasses)

anim2 = Sparkle(pixels, 0.05, PURPLE)

group = AnimationSequence(anim2,
                          advance_interval=5,
                          auto_reset=True,
                          auto_clear=True)
while True:
    group.animate()
Ejemplo n.º 4
0
              COMET_SPEED,
              color.TEAL,
              tail_length=STRIP_COMET_TAIL_LENGTH,
              bounce=STRIP_COMET_BOUNCE)),
)

animation_color = None
mode = 0
blanked = False

while True:
    ble.start_advertising(advertisement)  # Start advertising.
    was_connected = False
    while not was_connected or ble.connected:
        if not blanked:  # If LED-off signal is not being sent...
            animations.animate()  # Run the animations.
        if ble.connected:  # If BLE is connected...
            was_connected = True
            if uart.in_waiting:  # Check to see if any data is available.
                try:
                    packet = Packet.from_stream(
                        uart)  # Create the packet object.
                except ValueError:
                    continue
                if isinstance(packet,
                              ColorPacket):  # If the packet is color packet...
                    if mode == 0:  # And mode is 0...
                        animations.color = packet.color  # Update the animation to the color.
                        print("Color:", packet.color)
                        animation_color = packet.color  # Keep track of the current color...
                    elif mode == 1:  # Because if mode is 1...
from adafruit_led_animation.color import RED, BLUE

# Update to match the pin connected to your NeoPixels
pixel_pin = board.D6
# Update to match the number of NeoPixels you have connected
pixel_num = 32

# Update to matchpin connected to button that connect logic high when pushed
button_pin = board.D3

pixels = neopixel.NeoPixel(pixel_pin,
                           pixel_num,
                           brightness=0.5,
                           auto_write=False)
button = DigitalInOut(button_pin)
button.direction = Direction.INPUT
button.pull = Pull.UP

solid_blue = Solid(pixels, color=BLUE)
solid_red = Solid(pixels, color=RED)
animation_sequence = AnimationSequence(solid_blue, solid_red, auto_clear=True)

while True:
    animation_sequence.animate()

    # Pressing the button pauses the animation permanently
    if not button.value:
        animation_sequence.next()
        while button.value:
            time.sleep(0.1)  # Used for button debouncing
Ejemplo n.º 6
0
animations = AnimationSequence(
    rainbow,
    rainbowfade,
    solid,
    sparkle,
    auto_clear=True,
    auto_reset=True,
)

solid.speed = 0.01
solid_color = 0

while True:
    if cp.switch:  # if slide switch is in the "on" position, run animations
        animations.animate()  #play animation sequence
        if cp.button_a:
            animations.next()
            while cp.button_a:
                continue

        if cp.button_b:
            if animations.current_animation.name == "solid":
                solid_color = (solid_color + 8) % 256
                animations.current_animation.color = colorwheel(solid_color)
            else:
                current_speed += 1
                if current_speed >= len(speeds):
                    current_speed = 0
                rainbow.speed = speeds[current_speed]
                sparkle.speed = speeds[current_speed]
                               auto_clear=False)

SERVO.angle = POSITION = NEXT_POSITION = 90
MOVING = False                # Initial state = paused
START_TIME = time.monotonic() # Initial time
DURATION = 1.0                # Hold initial position for 1 sec

while True: # Loop forever...

    # Move turret -- randomly looks around and pauses
    NOW = time.monotonic()
    ELAPSED = NOW - START_TIME # Seconds since start of motion or pause
    if ELAPSED >= DURATION:    # End motion/pause?
        MOVING = not MOVING    # Toggle between those two states
        START_TIME = NOW       # and record the new starting time
        ELAPSED = 0.0
        if MOVING:             # Switching from paused to moving
            POSITION = NEXT_POSITION
            while abs(POSITION - NEXT_POSITION) < 10:  # Min +/- 10 degrees
                NEXT_POSITION = random.uniform(0, 180) # Try, try again
            DURATION = 0.2 + 0.6 * abs(POSITION - NEXT_POSITION) / 180
        else:                  # Switching from moving to paused
            SERVO.angle = NEXT_POSITION         # Move to end of sweep
            DURATION = random.uniform(0.5, 2.5) # Pause time
    if MOVING:
        FRACTION = ELAPSED / DURATION                        # Linear 0 to 1
        FRACTION = (3 * FRACTION ** 2) - (2 * FRACTION ** 3) # Ease in/out
        SERVO.angle = POSITION + (NEXT_POSITION - POSITION) * FRACTION

    ANIMATIONS.animate() # Cycle through NeoPixel animations