From 64276b5e746fb8fa92fc9ead481a0b2df55c96d5 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Thu, 23 Sep 2021 14:32:08 -0400 Subject: [PATCH] Update examples to use rainbowio --- examples/rgbled_pca9685.py | 17 ++--------------- examples/rgbled_simpletest.py | 17 ++--------------- 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/examples/rgbled_pca9685.py b/examples/rgbled_pca9685.py index 9f40b91..425e801 100644 --- a/examples/rgbled_pca9685.py +++ b/examples/rgbled_pca9685.py @@ -4,6 +4,7 @@ import time import board import busio +from rainbowio import colorwheel import adafruit_pca9685 import adafruit_rgbled @@ -24,24 +25,10 @@ # led = adafruit_rgbled.RGBLED(RED_LED, GREEN_LED, BLUE_LED, invert_pwm=True) -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colours are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return 0, 0, 0 - if pos < 85: - return int(255 - pos * 3), int(pos * 3), 0 - if pos < 170: - pos -= 85 - return 0, int(255 - pos * 3), int(pos * 3) - pos -= 170 - return int(pos * 3), 0, int(255 - (pos * 3)) - - def rainbow_cycle(wait): for i in range(255): i = (i + 1) % 256 - led.color = wheel(i) + led.color = colorwheel(i) time.sleep(wait) diff --git a/examples/rgbled_simpletest.py b/examples/rgbled_simpletest.py index afd8baf..7d3ae63 100644 --- a/examples/rgbled_simpletest.py +++ b/examples/rgbled_simpletest.py @@ -3,6 +3,7 @@ import time import board +from rainbowio import colorwheel import adafruit_rgbled # Pin the Red LED is connected to @@ -21,24 +22,10 @@ # led = adafruit_rgbled.RGBLED(RED_LED, GREEN_LED, BLUE_LED, invert_pwm=True) -def wheel(pos): - # Input a value 0 to 255 to get a color value. - # The colours are a transition r - g - b - back to r. - if pos < 0 or pos > 255: - return 0, 0, 0 - if pos < 85: - return int(255 - pos * 3), int(pos * 3), 0 - if pos < 170: - pos -= 85 - return 0, int(255 - pos * 3), int(pos * 3) - pos -= 170 - return int(pos * 3), 0, int(255 - (pos * 3)) - - def rainbow_cycle(wait): for i in range(255): i = (i + 1) % 256 - led.color = wheel(i) + led.color = colorwheel(i) time.sleep(wait)