def piperColorWheel(hue_value, bright_value=100): if (bright_value < 3): return 0 if (bright_value >= 100): return colorwheel(int(hue_value) & 255) bright_value /= 100.0 hue_value = colorwheel(int(hue_value) & 255) bv_a = int(((hue_value) & 255) * bright_value) & 255 bv_b = int(((hue_value >> 8) & 255) * bright_value) & 255 bv_c = int(((hue_value >> 16) & 255) * bright_value) & 255 return (bv_a, bv_b, bv_c)
def rainbow_cycle(wait): for j in range(255): for i in range(len(strip)): idx = int((i * 256 / len(strip)) + j) strip[i] = colorwheel(idx & 255) strip.show() time.sleep(wait)
def rainbow(delay): for color_value in range(255): for led in range(1): pixel_index = (led * 256 // 1) + color_value pixel[led] = colorwheel(pixel_index & 255) pixel.show() time.sleep(delay)
def rainbow(wait): for j in range(255): for i in range(len(pixels)): idx = int(i + j) pixels[i] = colorwheel(idx & 255) pixels.show() time.sleep(wait)
def rainbow_cycle(seq): """Rainbow cycle generator""" rainbow_sequence = cycle_sequence(seq) while True: # pylint: disable=stop-iteration-return led[0] = (colorwheel(next(rainbow_sequence))) yield
def rainbow_cycle(delay): for j in range(255): for i in range(NUM_PIXELS): pixel_index = (i * 256 // NUM_PIXELS) + j pixels[i] = colorwheel(pixel_index & 255) pixels.show() time.sleep(delay)
def rainbow_fill(wait): for j in range(255): for i in range(num_pixels): pixel_index = int(i + j) pixels[i] = colorwheel(pixel_index & 255) pixels.show() time.sleep(wait)
def rainbow(delay): for color_value in range(255): for led in range(NUMBER_OF_PIXELS): pixel_index = (led * 256 // NUMBER_OF_PIXELS) + color_value dots[led] = colorwheel(pixel_index & 255) dots.show() time.sleep(delay)
def rainbow_cycle(wait): for j in range(255): for i in range(cp.pixels.n): idx = int((i * 256 / len(cp.pixels)) + j) cp.pixels[i] = colorwheel(idx & 255) cp.pixels.show() time.sleep(wait)
def rainbow(speed): for j in range(255): for i in range(num_pixels): pixel_index = (i * 256 // num_pixels) + j pixels[i] = colorwheel(pixel_index & 255) pixels.show() time.sleep(speed)
def rainbow_hold(wait): for j in range(255 * 1): # 3 cycles of all colors on colorwheel for r in range(len(pixels)): idx = int((r * 255 / len(pixels)) + j) pixels[r] = colorwheel(idx & 255) pixels.write() time.sleep(wait)
def rainbow(wait): for j in range(255): for index in range(len(pixels)): idx = int(index + j) pixels[index] = colorwheel(idx & 255) pixels.write() time.sleep(wait)
def rainbow_cycle(wait): for j in range(255): for i in range(num_pixels): rc_index = (i * 256 // num_pixels) + j pixels[i] = colorwheel(rc_index & 255) pixels.show() time.sleep(wait)
def rainbow_cycle(wait): """Rainbow cycle animation. Cycles across all pixels.""" for color_index in range(255): for pixel in range(num_pixels): pixel_index = (pixel * 256 // num_pixels) + color_index pixels[pixel] = colorwheel(pixel_index & 255) pixels.show() time.sleep(wait)
async def rainbow_cycle(controls): """Rainbow cycle animation on ring one.""" while True: for j in range(255, -1, -1) if controls.reverse else range(0, 256, 1): for i in range(num_pixels): rc_index = (i * 256 // num_pixels) + j ring_one[i] = colorwheel(rc_index & 255) ring_one.show() await asyncio.sleep(controls.wait)
async def rainbow_cycle(controls): while True: # Increment by 2 instead of 1 to speed the cycle up a bit. for j in range(255, -1, -2) if controls.reverse else range(0, 256, 2): for i in range(num_pixels): rc_index = (i * 256 // num_pixels) + j pixels[i] = colorwheel(rc_index & 255) pixels.show() await asyncio.sleep(controls.wait)
def main(): # This precomputes the color palette for maximum speed # You could change it to compute the color palette of your choice w = [colorwheel(i) for i in range(256)] # This sets up the initial wave as a smooth gradient u = np.zeros(num_pixels) um = np.zeros(num_pixels) f = np.zeros(num_pixels) slope = np.linspace(0, 256, num=num_pixels) th = 1 # the first time is always random (is that a contradiction?) r = 0 while True: # Some of the time, add a random new wave to the mix # increase .15 to add waves more often # decrease it to add waves less often if r < .01: ii = random.randrange(1, num_pixels - 1) # increase 2 to make bigger waves f[ii] = (random.random() - .5) * 2 # Here's where to change dx, dt, and c # try .2, .02, 2 for relaxed # try 1., .7, .2 for very busy / almost random u, um = step(u, um, f, num_pixels, .1, .02, 1), u v = u * 200000 + slope + th for i, vi in enumerate(v): # Scale up by an empirical value, rotate by th, and look up the color pixels[i] = w[round(vi) % 256] # Take away a portion of the energy of the waves so they don't get out # of control u = u * .99 # incrementing th causes the colorwheel to slowly cycle even if nothing else is happening th = (th + .25) % 256 pixels.show() # Clear out the old random value, if any f[ii] = 0 # and get a new random value r = random.random()
def timed_rainbow_cycle(seconds, wait): # Get the starting time in seconds. start = time.monotonic() # Use a counter to increment the current color position. j = 0 # Loop until it's time to stop (desired number of milliseconds have elapsed). while (time.monotonic() - start) < seconds: for i in range(len(strip)): idx = int((i * 256 / len(strip)) + j) strip[i] = colorwheel(idx & 255) strip.show() # Wait the desired number of milliseconds. time.sleep(wait) j += 1 # Turn all the pixels off after the animation is done. for i in range(len(strip)): strip[i] = (0, 0, 0) strip.show()
def scroll(t, b): # Add spaces to the start and end of each label so that it goes from # the far right all the way off the left sp = b' ' * linelen t = sp + t + sp b = sp + b + sp maxlen = max(len(t), len(b)) # For each whole character position... for i in range(maxlen - linelen): # Set the letter displayed at each position, and its color for j in range(linelen): sh[j][1] = colorwheel(3 * (2 * i + j)) tg1[j][0] = charmap[t[i + j]] tg2[j][0] = charmap[b[i + j]] # And then for each pixel position, move the two labels # and then refresh the display. for j in range(7): l1.x = -j l2.x = -j display.refresh(minimum_frames_per_second=0)
import rainbowio for i in range(0, 256, 15): print("{:3} {:06x} {:06x}".format(i, rainbowio.colorwheel(i), rainbowio.colorwheel(float(i)))) for i in range(256, 1024, 128): print("{:3} {:06x}".format(i, rainbowio.colorwheel(i)))
def rainbow(delay): for color_value in range(255): pixel[0] = colorwheel(color_value) time.sleep(delay)
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT import board from rainbowio import colorwheel from adafruit_is31fl3741.adafruit_ledglasses import LED_Glasses import adafruit_is31fl3741 glasses = LED_Glasses(board.I2C(), allocate=adafruit_is31fl3741.MUST_BUFFER) wheeloffset = 0 while True: for i in range(24): hue = colorwheel(i * 256 // 24 + wheeloffset) glasses.right_ring[i] = hue glasses.left_ring[23 - i] = hue glasses.show() wheeloffset += 10
def rainbow(color_index): for led in range(4): pixel_index = (led * 256 // 4) + color_index pixels[led] = colorwheel(pixel_index & 255) pixels.show()
board.KEY7, board.KEY8, board.KEY9, board.KEY10, board.KEY11, board.KEY12) keys = keypad.Keys(key_pins, value_when_pressed=False, pull=True) encoder = rotaryio.IncrementalEncoder(board.ROTA, board.ROTB) button = digitalio.DigitalInOut(board.BUTTON) button.switch_to_input(pull=digitalio.Pull.UP) pixels = neopixel.NeoPixel(board.NEOPIXEL, 12, brightness=0.2) last_position = None while True: if not button.value: pixels.brightness = 1.0 else: pixels.brightness = 0.2 position = encoder.position if last_position is None or position != last_position: print("Rotary:", position) last_position = position color_value = (position * 2) % 255 event = keys.events.get() if event: print(event) if event.pressed: pixels[event.key_number] = colorwheel(color_value) else: pixels[event.key_number] = 0
black_left, black_right, ), black_left, auto_clear=True, auto_reset=True, ) MODE = 0 LASTMODE = 1 i = 0 # Main loop while True: i = (i + 0.5) % 256 # run from 0 to 255 TILT_COLOR = colorwheel(i) if MODE == 0: # If currently off... enable.value = True power_on(POWER_ON_DURATION) # Power up! MODE = LASTMODE elif MODE >= 1: # If not OFF MODE... # Read button cur_state = btn.value if cur_state != prev_state: if not cur_state: animations.next() print("BTN is down") else: print("BTN is up") prev_state = cur_state
# Figure out how 'wide' each range is leftSpan = leftMax - leftMin rightSpan = rightMax - rightMin # Convert the left range into a 0-1 range (int) valueScaled = int(value - leftMin) / int(leftSpan) # Convert the 0-1 range into a value in the right range. return int(rightMin + (valueScaled * rightSpan)) while True: n = int((mic_pin.value / 65536) * 1000) # 10-bit ADC format n = abs(n - 512 - dc_offset) # Center on zero if n >= noise: # Remove noise/hum n = n - noise # "Dampened" reading (else looks twitchy) - divide by 8 (2^3) lvl = int(((lvl * 7) + n) / 8) # Color pixels based on rainbow gradient vlvl = remapRangeSafe(lvl, 0, 255, wheelStart, wheelEnd) for i in range(0, len(strip)): strip[i] = colorwheel(vlvl) # Set strip brightness based oncode audio level brightness = remapRangeSafe(lvl, 50, 255, 0, maxbrt) strip.brightness = float(brightness) / 255.0 strip.show()
pixel.brightness = 0.5 last_position = -1 color = 0 # start at red while True: # negate the position to make clockwise rotation positive position = -encoder.position if position != last_position: print(position) if switch.value: # Change the LED color. if position > last_position: # Advance forward through the colorwheel. color += 1 else: color -= 1 # Advance backward through the colorwheel. color = (color + 256) % 256 # wrap around to 0-256 pixel.fill(colorwheel(color)) else: # If the button is pressed... # ...change the brightness. if position > last_position: # Increase the brightness. pixel.brightness = min(1.0, pixel.brightness + 0.1) else: # Decrease the brightness. pixel.brightness = max(0, pixel.brightness - 0.1) last_position = position
def rainbow_lamp(seq): g = cycle_sequence(seq) while True: strip.fill(colorwheel(next(g))) strip.show() yield
import time from rainbowio import colorwheel import adafruit_dotstar import board # For Trinket M0, Gemma M0, and ItsyBitsy M0 Express led = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1) # For Feather M0 Express, Metro M0 Express, and Circuit Playground Express # led = neopixel.NeoPixel(board.NEOPIXEL, 1) led.brightness = 0.3 i = 0 while True: i = (i + 1) % 256 # run from 0 to 255 led.fill(colorwheel(i)) time.sleep(0.1)
scale=1, background_color=0x000000, ) reg_label.anchor_point = (0.5, 0.5) reg_label.anchored_position = (display.width // 2, display.height // 2) rainbow_bitmap = displayio.Bitmap( reg_label.bounding_box[2] * reg_label.scale, reg_label.bounding_box[3] * reg_label.scale, 255, ) rainbow_palette = displayio.Palette(255) for i in range(0, 255): rainbow_palette[i] = colorwheel(i) for y in range(rainbow_bitmap.height): for x in range(rainbow_bitmap.width): rainbow_bitmap[x, y] = max(1, (x + 1) % 255) bg_tilegrid = displayio.TileGrid(rainbow_bitmap, pixel_shader=rainbow_palette) print(reg_label.bounding_box[0]) bg_tilegrid.x = reg_label.x + 1 bg_tilegrid.y = reg_label.y - 8 main_group.append(bg_tilegrid) main_group.append(reg_label) while True: