def active_incident(pixels, eul, inveul, brightness): barsize = round(STATUS_VARS['NUMPIXELS'] / 4) barcolor = (255, 0, 0) dimbarcolor = (25, 0, 0) for k in range(5): for i in range(pixels.n - barsize): pixels.fill((0, 0, 0)) pixels[i] = dimbarcolor for j in range(barsize): pixels[i + j] = barcolor #pixels[i + barsize + 1] = dimbarcolor pixels.show() time.sleep(0.01) #Set up gradient pallete and constant values grad = [(0.0, STATUS_VARS['UNHEALTHY_COLOR']), (1.0, STATUS_VARS['UNHEALTHY_COLOR'])] palette = fancy.expand_gradient(grad, 64) whiletimeout = time.time() + 20 while True: if time.time() > whiletimeout: break breathe_lights(pixels, palette, eul, inveul, brightness)
def run_lights(threadname, ): #Initialize Neopixels pixels = neopixel.NeoPixel(board.D18, STATUS_VARS['NUMPIXELS'], auto_write=False, brightness=STATUS_VARS['MAXBRIGHTNESS']) #Set up gradient pallete and constant values grad = [(0.0, STATUS_VARS['HEALTHY_COLOR']), (1.0, STATUS_VARS['UNHEALTHY_COLOR'])] palette = fancy.expand_gradient(grad, 64) #print(fancy.palette_lookup(palette, 64)) eul = math.e inveul = 1 / math.e brightness = 0.8 #TODO: Figure out relationship of speed to duty cycle for calculating steps in the loop #SPEED=1.0 #Run loop while True: onStatus = shouldIBeOn() if not onStatus: pixels.fill((0, 0, 0)) pixels.show() elif onStatus: if STATUS_VARS['SEVERITY_VALUE'] == -1.0: loading_lights(pixels) elif STATUS_VARS['CURRENT_INCIDENT']: active_incident(pixels, eul, inveul, brightness) else: #active_incident(pixels, eul, inveul, brightness) breathe_lights(pixels, palette, eul, inveul, brightness)
def __init__(self, strip): # refer to # https://learn.adafruit.com/fancyled-library-for-circuitpython/led-colors # across the rainbow self.strip = strip self.lookup = [] self.size = self.strip.n / 2 grad = [(0.0, 0xFF0000), (0.33, 0x00FF00), (0.67, 0x0000FF), (1.0, 0xFF0000)] palette = fancy.expand_gradient(grad, 20) for index in range(self.size): coloff = index / self.size rgb = fancy.palette_lookup(palette, coloff) color = rgb.pack() self.lookup.append(color) # delete to free memory grad and palette we don't them any longer del grad del palette
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)
pin.pull = Pull.UP switch = Debouncer(pin) pixels = NeoPixel(NEOPIXEL, 1) # Set up built-in NeoPixel AQUA = 0x00FFFF # (0, 255, 255) GREEN = 0x00FF00 # (0, 255, 0) ORANGE = 0xFF8000 # (255, 128, 0) RED = 0xFF0000 # (255, 0, 0) BLUE = 0x0000FF # (0, 0, 255) gradients = { 'Off': [(0.0, RED), (0.75, ORANGE)], 'On': [(0.0, GREEN), (1.0, AQUA)] } palette = fancy.expand_gradient(gradients['Off'], 30) gamma_levels = (0.25, 0.3, 0.15) color_index = 1 fade_direction = 1 ble = BLERadio() TARGET = 'dd:22:0c:b5:80:e0' # CHANGE TO YOUR BLE ADDRESS button_packet = ButtonPacket("1", True) # Transmits pressed button 1 # scanner = Scanner() # BLE Scanner # uart_client = UARTClient() # BLE Client uart_connection = None # See if any existing connections are providing UARTService.
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 image_group = displayio.Group(scale=4) image_group.append(image_tile) scale_bitmap = displayio.Bitmap( number_of_colors, 1, number_of_colors ) # Create a Group Scale must be 128 divided by number_of_colors scale_group = displayio.Group(scale=2)
from adafruit_ntp import NTP import adafruit_fancyled.adafruit_fancyled as fancy # Station names associated with each LED # Note CXHM does not report snow so I use CTBF STATION_LIST = [ 'CTZR', 'CXHA', 'CXRG', 'CWSN', 'CTBF', 'CTWL', 'CWNC', 'CTKG', 'CTBO', 'CXKE', 'CTCK', 'CWGD', 'CZEL', 'CTBF', 'CXTO', 'CTUX', 'CTPQ', 'CWRK', 'CTPM', 'CXOA', 'CTNK', 'CTZN', 'CTSB', 'COSM', 'CTZE', 'CTTR', 'CWLS', 'CXET', 'CTBT', 'CXPC' ] # Colour constants grad = [(0.0, 0xedf8b1), (0.5, 0x9ebcda), (1.0, 0x0000FF)] levels = (0.25, 0.3, 0.15) palette = fancy.expand_gradient(grad, 50) BASE_URL = 'https://dd.weather.gc.ca/observations/swob-ml/' VAR_STRING = 'avg_snw_dpth_pst5mts' latest_var = [None] * len(STATION_LIST) # Init pixels pixels = neopixel.NeoPixel(board.D5, 30, brightness=0.5, auto_write=True, pixel_order=neopixel.GRBW) pixels.fill((255, 0, 0, 0)) # Check for WIFI creds try: