/ Gemma_Nano_Ring / code.py
code.py
1 # SPDX-FileCopyrightText: 2017 Mikey Sklar for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 import time 6 7 import board 8 import neopixel 9 10 try: 11 import urandom as random 12 except ImportError: 13 import random 14 15 numpix = 3 # Number of NeoPixels 16 pixpin = board.D1 # Pin where NeoPixels are connected 17 strip = neopixel.NeoPixel(pixpin, numpix, brightness=.1, auto_write=True) 18 colors = [ 19 [30, 144, 255], # Dodger Blue 20 [232, 100, 255], # Purple 21 [204, 0, 204], # Pink 22 [200, 200, 20], # Yellow 23 [30, 200, 200], # Blue 24 ] 25 26 27 def flash_random(wait, howmany): 28 for _ in range(howmany): 29 30 c = random.randint(0, len(colors) - 1) # Choose random color index 31 j = random.randint(0, numpix - 1) # Choose random pixel 32 strip[j] = colors[c] # Set pixel to color 33 34 for i in range(1, 5): 35 strip.brightness = i / 5.0 # Ramp up brightness 36 time.sleep(wait) 37 38 for i in range(5, 0, -1): 39 strip.brightness = i / 5.0 # Ramp down brightness 40 time.sleep(wait) 41 strip[j] = [0, 0, 0] # Set pixel to 'off' 42 43 while True: 44 # first number is 'wait' delay, shorter num == shorter twinkle 45 flash_random(.01, 1) 46 # second number is how many neopixels to simultaneously light up 47 flash_random(.01, 3) 48 flash_random(.01, 2)