def ColorFromPalette(pal, pos, brightness=255, blend=False):
    """Approximates the FastLED ColorFromPalette() function

    ACCEPTS: color palette (list of CRGB, CSHV and/or packed ints),
             palette index (x16) + blend factor of next index (0-15) --
             e.g. pass 32 to retrieve palette index 2, or 40 for an
             interpolated value between palette index 2 and 3, optional
             brightness (0-255), optional blend flag (True/False)

    RETURNS: CRGB color, no gamma correction
    """

    # Alter 'pos' from FastLED-like behavior to fancyled range
    if blend:
        # Continuous interpolation 0.0 to 1.0
        pos = (pos / 16.0) / len(pal)
    else:
        # No blending -- quantize to nearest palette bin
        pos = floor(pos / 16.0) / len(pal)

    color = fancy.palette_lookup(pal, pos)

    if brightness < 1.0:
        brightness /= 255.0
        if isinstance(color, fancy.CHSV):
            color = fancy.CRGB(color)
        elif isinstance(color, int):
            color = fancy.unpack(color)
        color.red *= brightness
        color.green *= brightness
        color.blue *= brightness

    return color
示例#2
0
 def __init__(self, t):
     self.totalled = t
     self.ledStrip = adafruit_dotstar.DotStar(board.SCK,
                                              board.MOSI,
                                              self.totalled,
                                              brightness=1,
                                              auto_write=False)
     self.ledStrip.fill(fancy.CRGB(0.0, 0.0, 0.0))
     self.ledStrip.show()
def hsv2rgb_spectrum(hue, sat, val):
    """This is named the same thing as FastLED's simpler HSV to RGB function
    (spectrum, vs rainbow) but implementation is a bit different for the
    sake of getting something running (adapted from some NeoPixel code).

    ACCEPTS: hue, saturation, value in range 0 to 255
    RETURNS: CRGB color.
    """

    return fancy.CRGB(fancy.CHSV(hue / 255, sat / 255, val / 255))
def led_drops(strip):

    # FancyLED allows for mixing colors with palettes
    palette = [fancy.CRGB(200, 255, 200),       # lighter (more white) green
               fancy.CRGB(0, 255, 0)]           # full green

    for i in range(num_leds):
        # FancyLED can handle the gamma adjustment, brightness and RGB settings
        color = fancy.palette_lookup(palette, i / num_leds)
        color = fancy.gamma_adjust(color, brightness=brightness)
        strip[i] = color.pack()

        # turn off the LEDs as we go for raindrop effect
        if  i >= concurrent:
            strip[i - concurrent] = (0,0,0)

        if i >= num_leds - 1:
            for j in range(concurrent,-1,-1):
                strip[i-j] = (0,0,0)
                time.sleep(on_time)

        time.sleep(on_time)
示例#5
0
    def start_colors(self, environ):
        print("start colors")
        json = json_module.loads(environ["wsgi.input"].getvalue())
        if json and json.get("colors"):
            colors = json.get("colors")
            if json.get("blend"):
                self.palette = []
                for color in colors:
                    print(color)
                    self.palette.append(fancy.CRGB(color.get("r"),color.get("g"), color.get("b")))
            self.period = json.get("period") if json.get("period") else 0
            self.duty_cycle = json.get("duty_cycle") if json.get("duty_cycle") else 1

            if json.get("animate"):
                self.is_displaying = display_type.COLORS_GRAD_ANIMATE
                return ("200 OK", [], [])
            
            partition_size = num_pixels // len(colors)
            remainder = num_pixels % len(colors)
            if json.get("blend"):
                for i in range(num_pixels):
                    pos = (i / ((num_pixels * len(colors)) / (len(colors) - 1) ) )
                    color = fancy.palette_lookup(self.palette, pos)
                    print('pos', pos)
                    print('color', color)
                    color = fancy.gamma_adjust(color, brightness=0.5)
                    self.colors_pixels[i] = color.pack()
            else:
                for idx, color in enumerate(colors):
                    color = fancy.CRGB(color.get("r"),color.get("g"), color.get("b"))
                    # color = fancy.gamma_adjust(color, brightness=0.5)
                    current_idx = idx * partition_size
                    use_remainder = remainder if idx == len(colors) - 1 else 0

                    self.colors_pixels[current_idx: current_idx + partition_size + use_remainder] = [color.pack()] * (partition_size + use_remainder)
            self.is_displaying = display_type.COLORS
        return ("200 OK", [], [])
示例#6
0
def blend(palette1, palette2, weight2, offset):
    """ Given two FancyLED color palettes and a weighting (0.0 to 1.0) of
        the second palette, plus a positional offset (where 0.0 is the start
        of each palette), fill the NeoPixel strip with an interpolated blend
        of the two palettes.
    """
    weight2 = min(1.0, max(0.0, weight2))  # Constrain input to 0.0-1.0
    weight1 = 1.0 - weight2  # palette1 weight (inverse of #2)
    for i in range(NUM_LEDS):
        position = offset + i / NUM_LEDS
        color1 = fancy.palette_lookup(palette1, position)
        color2 = fancy.palette_lookup(palette2, position)
        # Blend the two colors based on weight1&2, run through gamma func:
        color = fancy.CRGB(color1[0] * weight1 + color2[0] * weight2,
                           color1[1] * weight1 + color2[1] * weight2,
                           color1[2] * weight1 + color2[2] * weight2)
        color = fancy.gamma_adjust(color, brightness=BRIGHTNESS)
        PIXELS[i] = color.pack()
    PIXELS.show()
示例#7
0
    def __init__(
            self,
            pixels,
            colors,
            x_range=None,
            y_range=None,
            value=0,
            min_value=0,
            speed=0.05,
            brightness=BRIGHTNESS,
            palette_shift_speed=None,
            palette_scale=1.0,
            background_color=fancy.CRGB(0, 0, 0),
            positions=None,
            color_from_end=False,
            highlight=None,
            highlight_color=fancy.CHSV(0, 0, 1.0),
            highlight_speed=1,
            t=time.monotonic(),
    ):
        self.pixels = pixels
        self.speed = speed
        self.palette_shift_speed = palette_shift_speed
        self.palette_scale = palette_scale
        self.colors = colors if type(colors) is list else [colors]
        self.background_color = background_color
        self.color_from_end = color_from_end
        self.highlight = highlight
        self.highlight_color = highlight_color
        self.highlight_speed = highlight_speed
        self.highlight_t = 0

        self.set_position(x_range, y_range, positions)

        self.brightness = brightness

        self.rendered_value = 0
        self.dirty = False
        self.value = value
        self.min_value = min_value
        self.last_value = value
        self.last_value_t = t
示例#8
0
def loadDynamicGradientPalette(src, size):
    """ Kindasorta like FastLED's loadDynamicGradientPalette() function,
    with some gotchas.

    ACCEPTS: Gradient palette data as a 'bytes' type (makes it easier to copy
             over gradient palettes from existing FastLED Arduino sketches)...
             each palette entry is four bytes: a relative position (0-255)
             within the overall resulting palette (whatever its size), and
             3 values for R, G and B...and a length for a new palette list
             to be allocated.

    RETURNS: list of CRGB colors.
    """

    # Convert gradient from bytelist (groups of 4) to list of tuples,
    # each consisting of a position (0.0 to 1.0) and CRGB color.
    # (This is what FancyLED's expand_gradient needs for input.)
    grad = []
    for i in range(0, len(src), 4):
        grad.append((src[i] / 255.0, fancy.CRGB(src[i+1], src[i+2], src[i+3])))

    # Create palette (CRGB list) matching 'size' length
    return fancy.expand_gradient(grad, size)
示例#9
0
# delare variables and settings
strip = neopixel.NeoPixel(board.D1, 10, auto_write=False)
ledMode = 0

button = DigitalInOut(board.A1)
button.direction = Direction.INPUT
button.pull = Pull.DOWN
buttonPre = False
buttonPressTime = 0

cpx.pixels.auto_write = False  # Update only when we say
cpx.pixels.fill((0, 0, 0))  # Turn off the NeoPixels if they're on!
cpx.pixels.brightness = 0.1  # make less blinding

palette = [
    fancy.CRGB(251, 126, 253),  # pink
    fancy.CRGB(184, 22, 180),  # purple
    fancy.CRGB(227, 37, 107),  # violet red
    fancy.CRGB(0, 0, 0)
]  # Black

offset = 0  # Position offset into palette to make it "spin"

while True:
    if button.value != buttonPre:
        buttonPre = button.value
        if button.value:
            buttonPressTime = time.monotonic()
        else:
            if time.monotonic() >= buttonPressTime + 1:
                ledMode = 0
示例#10
0
from adafruit_ble.services.nordic import UARTService

from adafruit_bluefruit_connect.packet import Packet
from adafruit_bluefruit_connect.button_packet import ButtonPacket
from adafruit_bluefruit_connect.color_packet import ColorPacket

NUM_LEDS = 60  # change to reflect your LED strip
NEOPIXEL_PIN = board.D13  # change to reflect your wiring

# Palettes can have any number of elements in various formats
# check https://learn.adafruit.com/fancyled-library-for-circuitpython/colors
# for more info

# Declare a 6-element RGB rainbow palette
PALETTE_RAINBOW = [
    fancy.CRGB(1.0, 0.0, 0.0),  # Red
    fancy.CRGB(0.5, 0.5, 0.0),  # Yellow
    fancy.CRGB(0.0, 1.0, 0.0),  # Green
    fancy.CRGB(0.0, 0.5, 0.5),  # Cyan
    fancy.CRGB(0.0, 0.0, 1.0),  # Blue
    fancy.CRGB(0.5, 0.0, 0.5)
]  # Magenta

# Declare a Purple Gradient palette
PALETTE_GRADIENT = [
    fancy.CRGB(160, 0, 141),  # Purples
    fancy.CRGB(77, 0, 160),
    fancy.CRGB(124, 0, 255),
    fancy.CRGB(0, 68, 214)
]
NEOPIXEL_PIN = board.D6
NEOPIXEL_NUM = 31
pixels = neopixel.NeoPixel(NEOPIXEL_PIN, NEOPIXEL_NUM, auto_write=False)

# Since its common anode, 'off' is max duty cycle
red_led = pwmio.PWMOut(board.D9, frequency=5000, duty_cycle=65535)
green_led = pwmio.PWMOut(board.D10, frequency=5000, duty_cycle=65535)
blue_led = pwmio.PWMOut(board.D11, frequency=5000, duty_cycle=65535)

switch = DigitalInOut(board.D12)
switch.direction = Direction.INPUT
switch.pull = Pull.UP

colorways = [
    fancy.CRGB(1.0, 1.0, 1.0),  # White
    fancy.CRGB(1.0, 0.0, 0.0),  # Red
    fancy.CRGB(0.5, 0.5, 0.0),  # Yellow
    fancy.CRGB(0.0, 1.0, 0.0),  # Green
    fancy.CRGB(0.0, 0.5, 0.5),  # Cyan
    fancy.CRGB(0.0, 0.0, 1.0),  # Blue
    fancy.CRGB(0.5, 0.0, 0.5),  # Magenta
    # you can also make lists of colors to cycle through, like red/green/blue:
    [
        fancy.CRGB(1.0, 0.0, 0.0),
        fancy.CRGB(0.0, 1.0, 0.0),
        fancy.CRGB(0.0, 0.0, 1.0)
    ],
    # or just white/blue
    [fancy.CRGB(1.0, 1.0, 1.0),
     fancy.CRGB(0.0, 0.0, 1.0)],
示例#12
0
import board
import time
import analogio
import neopixel
from adafruit_circuitplayground.express import cpx
import adafruit_fancyled.adafruit_fancyled as fancy

cpx.pixels.auto_write = False  # Update only when we say
cpx.pixels.fill((0, 0, 0))  # Turn off the NeoPixels if they're on!
cpx.pixels.brightness = 0.1  # make less blinding

palette_purple = [
    fancy.CRGB(251, 126, 253),  # pink
    fancy.CRGB(138, 43, 226),  # purple
    fancy.CRGB(227, 37, 107),  # violet red
    fancy.CRGB(0, 0, 0)
]  # Black

palette_blue = [
    fancy.CRGB(83, 42, 133),  # evening red
    fancy.CRGB(38, 36, 96),  # midnight blue
    fancy.CRGB(6, 170, 252),  # bay blue
    fancy.CRGB(0, 0, 0)
]  # Black

offset = 0  # Position offset into palette to make it "spin"

analogIn_1 = analogio.AnalogIn(board.A1)
analogIn_2 = analogio.AnalogIn(board.A2)
analogIn_3 = analogio.AnalogIn(board.A3)
import time
from adafruit_circuitplayground import cp
import adafruit_fancyled.adafruit_fancyled as fancy

cp.pixels.brightness = 0.2 # 0.0 to 1.0 Overall brightness modifier

hue = 0.1
sat = 1.0
val = 1.0

color_RGB = fancy.denormalize( fancy.CRGB( fancy.CHSV( hue, sat, val ))) #collapse three steps

while True:
    index = 0
    while index < 10:
        print( index )
        cp.pixels[ index ] = color_RGB
        index = index + 1
        time.sleep( 0.5 )
import time
import board
import busio
import adafruit_mlx90640
import displayio
import terminalio
from adafruit_display_text.label import Label
from simpleio import map_range
import adafruit_fancyled.adafruit_fancyled as fancy

number_of_colors = 64                          # Number of color in the gradian
last_color = number_of_colors-1                # Last color in palette
palette = displayio.Palette(number_of_colors)  # Palette with all our colors

# gradian for fancyled palette generation
grad = [(0.00, fancy.CRGB(0, 0, 255)),    # Blue
        (0.25, fancy.CRGB(0, 255, 255)),
        (0.50, fancy.CRGB(0, 255, 0)),    # Green
        (0.75, fancy.CRGB(255, 255, 0)),
        (1.00, fancy.CRGB(255, 0, 0))]    # Red

# create our palette using fancyled expansion of our gradian
fancy_palette = fancy.expand_gradient(grad, number_of_colors)
for c in range(number_of_colors):
    palette[c] = fancy_palette[c].pack()

# Bitmap for colour coded thermal value
image_bitmap = displayio.Bitmap( 32, 24, number_of_colors )
# Create a TileGrid using the Bitmap and Palette
image_tile= displayio.TileGrid(image_bitmap, pixel_shader=palette)
# Create a Group that scale 32*24 to 128*96
示例#15
0
import _thread
import configparser
import board
import neopixel
import adafruit_fancyled.adafruit_fancyled as fancy

STATUS_VARS = {
    'NUMPIXELS': 16,  #Number of neopixels
    'PI_PIN': board.D18,  #Raspberry PI data pin
    'MAXBRIGHTNESS': 1.0,  #Neopixel default max brightness
    'STATUS_CHECK_DELAY': 30,  #Delay between polling for updated status JSON
    'SEVERITY_VALUE':
    -1.0,  #Global severity value to be passed between threads
    'RECENCY_VALUE':
    2.0,  #Recency value representing speed of breathing pattern
    'HEALTHY_COLOR': fancy.CRGB(0.0, 1.0, 0.0),  #Color for healthy GCP status
    'MEDIUM_COLOR': fancy.CRGB(1.0, 0.7, 1.0),  #Color for medium gradient
    'UNHEALTHY_COLOR': fancy.CRGB(1.0, 0.0,
                                  0.0),  #Color for unhealthy GCP status
    'CURRENT_INCIDENT': False,
    'WAKE_TIME': '07:45:00',
    'SLEEP_TIME': '17:00:00',
}


class gcpstatus:
    def __init__(self):
        self.url = 'https://status.cloud.google.com/incidents.json'
        self.status = 'public'

    def getStatus(self):
示例#16
0
""" Simple FancyLED example for Circuit Playground Express
"""

from adafruit_circuitplayground.express import cpx
import adafruit_fancyled.adafruit_fancyled as fancy

cpx.pixels.auto_write = False  # Refresh pixels only when we say
cpx.pixels.brightness = 1.0  # We'll use FancyLED's brightness controls

# Declare a 4-element color palette, this one happens to be a
# 'blackbody' palette -- good for heat maps and firey effects.
palette = [
    fancy.CRGB(1.0, 1.0, 1.0),  # White
    fancy.CRGB(1.0, 1.0, 0.0),  # Yellow
    fancy.CRGB(1.0, 0.0, 0.0),  # Red
    fancy.CRGB(0.0, 0.0, 0.0)
]  # Black

offset = 0  # Positional offset into color palette to get it to 'spin'
levels = (0.25, 0.3, 0.15)  # Color balance / brightness for gamma function

while True:
    for i in range(10):
        # Load each pixel's color from the palette using an offset, run it
        # through the gamma function, pack RGB value and assign to pixel.
        color = fancy.palette_lookup(palette, offset + i / 10)
        color = fancy.gamma_adjust(color, brightness=levels)
        cpx.pixels[i] = color.pack()
    cpx.pixels.show()

    offset += 0.033  # Bigger number = faster spin
示例#17
0
import time

num_leds = 1085
spread = 5

# Declare a NeoPixel object on pin D6 with num_leds pixels, no auto-write.
# Set brightness to max because we'll be using FancyLED's brightness control.

pixels = adafruit_dotstar.DotStar(board.SCK,
                                  board.MOSI,
                                  num_leds,
                                  brightness=1.0,
                                  auto_write=False)

offset = 0  # Positional offset into color palette to get it to 'spin'

blue = fancy.CRGB(0.0, 0.0, 1.0)  # Blue
red = fancy.CRGB(1.0, 0.0, 1.0)  # Pink
yellow = fancy.CRGB(1.0, 1.0, 0.0)  # Yellow

pixels.fill((0.0, 0.0, 1.0))
pixels.show()

time.sleep(3)

# pixels.

while True:
    pass
    #pixels.show()
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1,
                                 brightness=0.2)  # Uncomment  for Most Boards
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(
    esp, secrets, status_light)
pixels = neopixel.NeoPixel(board.D2, 150, brightness=1.0, auto_write=False)
pixels.fill(0x050505)
pixels.show()

# clouds palette
cloudy_palette = [
    fancy.CRGB(1.0, 1.0, 1.0),  # White
    fancy.CRGB(0.5, 0.5, 0.5),  # gray
    fancy.CRGB(0.5, 0.5, 1.0)
]  # blue-gray
# sunny palette
sunny_palette = [
    fancy.CRGB(1.0, 1.0, 1.0),  # White
    fancy.CRGB(1.0, 1.0, 0.0),  # Yellow
    fancy.CRGB(1.0, 0.5, 0.0),
]  # Orange
# thunderstorm palette
thunder_palette = [
    fancy.CRGB(0.0, 0.0, 1.0),  # blue
    fancy.CRGB(0.5, 0.5, 0.5),  # gray
    fancy.CRGB(0.5, 0.5, 1.0)
]  # blue-gray
示例#19
0
文件: main.py 项目: KEClaytor/Mordin
console = neopixel.NeoPixel(board.D0, 3, brightness=0.2, auto_write=False)
omnitool = neopixel.NeoPixel(board.D2, 1, brightness=0.3, auto_write=False)

button = button.Button(board.D4, digitalio.Pull.UP)

analog_out = analogio.AnalogOut(board.A0)

RED = (255, 0, 0)
YELLOW = (255, 150, 0)
GREEN = (0, 255, 0)
CYAN = (0, 255, 255)
BLUE = (0, 0, 255)
PURPLE = (180, 0, 255)
ORANGE = (255, 50, 0)

palette = [fancy.CRGB(*ORANGE), fancy.CRGB(*RED), fancy.CRGB(*BLUE)]


def buzz_till_button():
    """ Buzz until until a button press.
    """
    while not button.pressed():
        button.update()
        for _ in range(2):
            for ii in range(0, 65535, 64):
                analog_out.value = ii


def ternary_to_decimal(t):
    """ Convert a ternary key to a decimal.
    """
示例#20
0
MIN_TEMPO = 100
MAX_TEMPO = 300

SAMPLE_FOLDER = "/samples/"  # the name of the folder containing the samples
# You get 4 voices, they must all have the same sample rate and must
# all be mono or stereo (no mix-n-match!)
VOICES = [
    SAMPLE_FOLDER + "voice01.wav", SAMPLE_FOLDER + "voice02.wav",
    SAMPLE_FOLDER + "voice03.wav", SAMPLE_FOLDER + "voice04.wav"
]

# four colors for the 4 voices, using 0 or 255 only will reduce buzz
DRUM_COLOR = ((0, 255, 255), (0, 255, 0), (255, 255, 0), (255, 0, 0))
# For the intro, pick any number of colors to make a fancy gradient!
INTRO_SWIRL = [
    fancy.CRGB(255, 0, 0),  # red
    fancy.CRGB(0, 255, 0),  # green
    fancy.CRGB(0, 0, 255)
]  # blue
# the color for the sweeping ticker bar
TICKER_COLOR = (255, 255, 255)

# Our keypad + neopixel driver
trellis = adafruit_trellism4.TrellisM4Express(rotation=90)

# Our accelerometer
i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
accelerometer = adafruit_adxl34x.ADXL345(i2c)

# Play the welcome wav (if its there)
with audioio.AudioOut(board.A1, right_channel=board.A0) as audio:
示例#21
0
import time
import board
import analogio
from adafruit_circuitplayground import cp
import adafruit_fancyled.adafruit_fancyled as fancy

angle_sensor = analogio.AnalogIn(board.A1)

starting_color = (0, 0, 255)
OFF = (0, 0, 0)

cp.pixels.fill(starting_color)

while True:
    angle_normalized = round(angle_sensor.value / 65536, 3)
    print(angle_normalized)
    hue = angle_normalized
    color_hsv = fancy.CHSV(
        hue)  #input 0 to 1 for H, S, V :: OK to send only Hue
    color_RGB_normalized = fancy.CRGB(color_hsv)
    color_RGB = fancy.denormalize(color_RGB_normalized)
    cp.pixels.fill(color_RGB)
    time.sleep(0.2)
示例#22
0
from adafruit_circuitplayground.express import cpx
import adafruit_fancyled.adafruit_fancyled as fancy

cpx.pixels.auto_write = False  # Update only when we say
cpx.pixels.brightness = 0.15  # make less blinding

palette = [
    fancy.CRGB(255, 255, 255),  # White
    fancy.CRGB(0, 0, 255),  # Blue
    fancy.CRGB(255, 0, 0),  # Red
    fancy.CRGB(0, 0, 0)
]  # Black

offset = 0  # Position offset into palette to make it "spin"

while True:
    for i in range(10):
        color = fancy.palette_lookup(palette, offset + i / 9)
        color = fancy.gamma_adjust(color, brightness=0.25)
        cpx.pixels[i] = color.pack()
    cpx.pixels.show()

    offset += 0.033  # Bigger number = faster spin
while True:
    try:
        print("Fetching json from", DATA_SOURCE)
        response = wifi.get(DATA_SOURCE)
        print(response.json())
        value = response.json()
        for key in DATA_LOCATION:
            value = value[key]
            print(value)
        response.close()
    except (ValueError, RuntimeError) as e:
        print("Failed to get data, retrying\n", e)
        wifi.reset()
        continue

    if not value:
        continue
    if last_value != value:
        color = int(value[1:], 16)
        red = color >> 16 & 0xFF
        green = color >> 8 & 0xFF
        blue = color & 0xFF
        gamma_corrected = fancy.gamma_adjust(fancy.CRGB(red, green,
                                                        blue)).pack()

        pixels.fill(gamma_corrected)
        last_value = value
    response = None
    time.sleep(60)
示例#24
0
SAMPLE_FOLDER = "/samples/"  # the name of the folder containing the samples
# You get 4 voices, they must all have the same sample rate and must
# all be mono or stereo (no mix-n-match!)
VOICES = [SAMPLE_FOLDER+"voice01.wav",
          SAMPLE_FOLDER+"voice02.wav",
          SAMPLE_FOLDER+"voice03.wav",
          SAMPLE_FOLDER+"voice04.wav"]

# four colors for the 4 voices, using 0 or 255 only will reduce buzz
DRUM_COLOR = ((0, 255, 255),
              (0, 255, 0),
              (255, 255, 0),
              (255, 0, 0))
# For the intro, pick any number of colors to make a fancy gradient!
INTRO_SWIRL = [fancy.CRGB(255, 0, 0),  # red
               fancy.CRGB(0, 255, 0),  # green
               fancy.CRGB(0, 0, 255)]  # blue
# the color for the sweeping ticker bar
TICKER_COLOR = (255, 255, 255)

# Our keypad + neopixel driver
trellis = adafruit_trellism4.TrellisM4Express(rotation=90)

# Our accelerometer
i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
accelerometer = adafruit_adxl34x.ADXL345(i2c)

# Play the welcome wav (if its there)
with audioio.AudioOut(board.A1, right_channel=board.A0) as audio:
    try:
示例#25
0
        for address in uart_addresses:
            if TARGET in str(address):
                uart_client.connect(address, 5)  # Connect to target

    while uart_client.connected:  # Connected
        switch.update()
        if switch.fell:  # Check for button press
            try:
                uart_client.write(button_packet.to_bytes())  # Transmit press
            except OSError:
                pass
        # Check for LED status receipt
        if uart_client.in_waiting:
            packet = Packet.from_stream(uart_client)
            if isinstance(packet, ColorPacket):
                if fancy.CRGB(*packet.color).pack() == GREEN:  # Color match
                    # Green indicates on state
                    palette = fancy.expand_gradient(gradients['On'], 30)
                else:
                    # Otherwise red indicates off
                    palette = fancy.expand_gradient(gradients['Off'], 30)

        # NeoPixel color fading routing
        color = fancy.palette_lookup(palette, color_index / 29)
        color = fancy.gamma_adjust(color, brightness=gamma_levels)
        c = color.pack()
        pixels[0] = c
        pixels.show()
        if color_index == 0 or color_index == 28:
            fade_direction *= -1  # Change direction
        color_index += fade_direction
""" Simple FancyLED example for NeoPixel strip
"""

import board
import neopixel
import adafruit_fancyled.adafruit_fancyled as fancy

num_leds = 17

# Declare a Water Colors palette
palette = [
    fancy.CRGB(0, 214, 214),  # blues and cyans
    fancy.CRGB(0, 92, 160),
    fancy.CRGB(0, 123, 255),
    fancy.CRGB(0, 68, 214)
]

# Declare a Fire Colors palette
#palette = [fancy.CRGB(0, 0, 0),       # Black
#             fancy.CHSV(1.0),           # Red
#              fancy.CRGB(1.0, 1.0, 0.0), # Yellow
#              0xFFFFFF]                  # White

# Declare a NeoPixel object on pin D6 with num_leds pixels, no auto-write.
# Set brightness to max because we'll be using FancyLED's brightness control.
pixels = neopixel.NeoPixel(board.D1,
                           num_leds,
                           brightness=1.0,
                           auto_write=False)

offset = 0  # Positional offset into color palette to get it to 'spin'
示例#27
0
strip = neopixel.NeoPixel(led_pin, num_leds, brightness=1, auto_write=False)

# button setup
button = DigitalInOut(board.D2)
button.direction = Direction.INPUT
button.pull = Pull.UP
prevkeystate = False
ledmode = 0  # button press counter, switch color palettes

# FancyLED allows for assigning a color palette using these formats:
# * The first (5) palettes here are mixing between 2-elements
# * The last (3) palettes use a format identical to the FastLED Arduino Library
# see FastLED - colorpalettes.cpp

all_colors = [
    fancy.CRGB(0, 0, 0),  # black
    fancy.CRGB(255, 255, 255)
]  # white

allRed = [fancy.CRGB(255, 0, 0)]  #red

allGold = [0xFFD700]  #gold

allPurple = [fancy.CRGB(160, 32, 240)]  #purple

galaxy = [
    0x191970, 0x4B0082, 0x000000, 0x000000, 0x000080, 0x008080, 0x000000,
    0x000000, 0x008080, 0x4B0082, 0x000000, 0x000000, 0x000080, 0x008080,
    0x000000, 0x000000
]
示例#28
0
# We will be using FancyLED's brightness control.
strip = neopixel.NeoPixel(led_pin, num_leds, brightness=1, auto_write=False)

# button setup
button = DigitalInOut(board.A2)
button.direction = Direction.INPUT
button.pull = Pull.UP
prevkeystate = False
ledmode = 0  # button press counter, switch color palettes

# FancyLED allows for assigning a color palette using these formats:
# * The first (5) palettes here are mixing between 2-elements
# * The last (3) palettes use a format identical to the FastLED Arduino Library
# see FastLED - colorpalettes.cpp
forest = [
    fancy.CRGB(0, 255, 0),  # green
    fancy.CRGB(255, 255, 0)
]  # yellow

ocean = [
    fancy.CRGB(0, 0, 255),  # blue
    fancy.CRGB(0, 255, 0)
]  # green

purple = [
    fancy.CRGB(160, 32, 240),  # purple
    fancy.CRGB(238, 130, 238)
]  # violet

all_colors = [
    fancy.CRGB(0, 0, 0),  # black
示例#29
0
import adafruit_fancyled.adafruit_fancyled as fancy

RED_KEY = [fancy.CHSV(1.0, 0.5, 0.5), fancy.CHSV(1.0)]
YELLOW_KEY = [fancy.CHSV(1.0 / 6.0, 0.5, 0.5), fancy.CHSV(1.0 / 6.0)]
BLUE_KEY = [fancy.CHSV(0.6, 0.5, 0.5), fancy.CHSV(0.6)]

CHAINS = [
    fancy.CRGB(96, 149, 64),
    fancy.CRGB(234, 209, 83),
    fancy.CRGB(243, 169, 87),
    fancy.CRGB(178, 31, 31),
]
示例#30
0
    spi_miso=spi_miso,
    pixel_count=num_leds)

print("pixel_count", pixels.pixel_count)
print("chip_count", pixels.chip_count)
print("channel_count", pixels.channel_count)


##########################################
# helper function


##########################################
# Declare a 6-element RGB rainbow palette
palette = [
    fancyled.CRGB(1.0, 0.0, 0.0),  # Red
    fancyled.CRGB(0.5, 0.5, 0.0),  # Yellow
    fancyled.CRGB(0.0, 1.0, 0.0),  # Green
    fancyled.CRGB(0.0, 0.5, 0.5),  # Cyan
    fancyled.CRGB(0.0, 0.0, 1.0),  # Blue
    fancyled.CRGB(0.5, 0.0, 0.5),  # Magenta
]

# Positional offset into color palette to get it to 'spin'
offset = 0

##########################################
# main loop
print(42 * '*')
print("rainbow loop")
while True: