Simplify rainbow code

This commit is contained in:
Kattni Rembor 2022-02-08 13:22:49 -05:00
parent e5fc534b8d
commit 13f5649bd0
2 changed files with 4 additions and 11 deletions

View file

@ -1,7 +1,7 @@
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
# SPDX-License-Identifier: Unlicense # SPDX-License-Identifier: Unlicense
""" """
CircuitPython DotStar rainbow, brightness control example. CircuitPython DotStar red, green, blue, brightness control example.
""" """
import time import time
import board import board
@ -14,10 +14,7 @@ dot.brightness = 0.3
def rainbow(delay): def rainbow(delay):
for color_value in range(255): for color_value in range(255):
for led in range(1): dot[0] = colorwheel(color_value)
dot_index = (led * 256 // 1) + color_value
dot[led] = colorwheel(dot_index & 255)
dot.show()
time.sleep(delay) time.sleep(delay)

View file

@ -6,17 +6,13 @@ import board
from rainbowio import colorwheel from rainbowio import colorwheel
import neopixel import neopixel
pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, auto_write=False) pixel = neopixel.NeoPixel(board.NEOPIXEL, 1)
pixel.brightness = 0.3 pixel.brightness = 0.3
def rainbow(delay): def rainbow(delay):
for color_value in range(255): for color_value in range(255):
for led in range(1): pixel[0] = colorwheel(color_value)
pixel_index = (led * 256 // 1) + color_value
pixel[led] = colorwheel(pixel_index & 255)
pixel.show()
time.sleep(delay) time.sleep(delay)