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
senseVal = myfunction.scaleAndTranslate(analogIn_1.value, 0, 65535, 0, 1500) TH = int(senseVal) mic.record(samples, len(samples)) magnitude = myfunction.normalized_rms(samples) if magnitude > TH: ledMode += 1 if ledMode > 3: ledMode = 0 if ledMode == 1: for i in range(10): color = fancy.palette_lookup(myfunction.palette_purple, offset + i / 9) cpx.pixels[i] = color.pack() cpx.pixels.show() offset += 0.08 # Bigger number = faster spin time.sleep(0.01) if ledMode == 2: for i in range(10): color = fancy.palette_lookup(myfunction.palette_blue, offset + i / 9) cpx.pixels[i] = color.pack() cpx.pixels.show() offset += 0.08 # Bigger number = faster spin time.sleep(0.01) if ledMode == 3: