def step(): global COLOR_INDEX, DOTSTAR # Get the R,G,B values of the next colour r, g, b = TinyPICO.dotstar_color_wheel(COLOR_INDEX * 2) # Set the colour on the DOTSTAR DOTSTAR[0] = (int(r * 0.6), g, b, 0.4) # Increase the wheel index COLOR_INDEX = 0 if COLOR_INDEX > 1000 else COLOR_INDEX + 2
def wheel(br=None): global COLOR_INDEX __init_tinyrgb() br = DOTSTAR_STATE[1] if br is None else br # Get the R,G,B values of the next colour r, g, b = TinyPICO.dotstar_color_wheel(COLOR_INDEX * 3) # Set the colour on the DOTSTAR DOTSTAR[0] = (r, g, b, br) # Increase the wheel index COLOR_INDEX = 0 if COLOR_INDEX > 500 else COLOR_INDEX + 1 return "RGB: {}:{}:{} ({}%)".format(r, g, b, DOTSTAR_STATE[1] * 100)
def do_things(): # Create a colour wheel index int color_index = 0 # Rainbow colours on the Dotstar while True: # Get the R,G,B values of the next colour r, g, b = TinyPICO.dotstar_color_wheel(color_index) # Set the colour on the dotstar dotstar[0] = (r, g, b, 0.5) # Increase the wheel index color_index += 1 # Sleep for 20ms so the colour cycle isn't too fast time.sleep_ms(20) # Print the internal PICO-D4 temperature in C print_temp() # Connect / Maintain internet connection. do_connect(config) time.sleep_us(100)
# Get the amount of RAM and if it's correct, flash green 3 times before rainbow, otherwise flash red three times def check_ram(): gc.collect() ram = gc.mem_free() col = (255, 0, 0, 1) if ram > 4000000: col = (0, 255, 0, 1) for i in range(3): dotstar[0] = col time.sleep_ms(200) dotstar[0] = (0, 0, 0, 10) time.sleep_ms(50) time.sleep_ms(250) # Check the RAM check_ram() # Rainbow colours on the Dotstar while True: # Get the R,G,B values of the next colour r, g, b = TinyPICO.dotstar_color_wheel(color_index) # Set the colour on the dotstar dotstar[0] = (r, g, b, 0.5) # Increase the wheel index color_index += 1 # Sleep for 20ms so the colour cycle isn't too fast time.sleep_ms(20)
from machine import SoftSPI, Pin import tinypico as TinyPICO from micropython_dotstar import DotStar import time, random # Configure SPI for controlling the DotStar # Internally we are using software SPI for this as the pins being used are not hardware SPI pins spi = SoftSPI(sck=Pin(TinyPICO.DOTSTAR_CLK), mosi=Pin(TinyPICO.DOTSTAR_DATA), miso=Pin(TinyPICO.SPI_MISO)) # Create a DotStar instance dotstar = DotStar(spi, 1, brightness=0.5) # Just one DotStar, half brightness # Turn on the power to the DotStar TinyPICO.set_dotstar_power(True) # On and Off times in ms wait_on = 500 wait_off = 500 # Flash the Dotstar a random colour every second while True: # Pick a random colour from the colour wheel r, g, b = TinyPICO.dotstar_color_wheel(int(random.random() * 255)) # Display the colour for wait_on time then clear for wait_off time dotstar[0] = (r, g, b, 1) time.sleep_ms(wait_on) dotstar[0] = (0, 0, 0, 1) time.sleep_ms(wait_off)