/ examples / rgbled_simpletest.py
rgbled_simpletest.py
 1  import time
 2  import board
 3  import adafruit_rgbled
 4  
 5  # Pin the Red LED is connected to
 6  RED_LED = board.D5
 7  
 8  # Pin the Green LED is connected to
 9  GREEN_LED = board.D6
10  
11  # Pin the Blue LED is connected to
12  BLUE_LED = board.D7
13  
14  # Create the RGB LED object
15  led = adafruit_rgbled.RGBLED(RED_LED, GREEN_LED, BLUE_LED)
16  
17  # Optionally, you can also create the RGB LED object with inverted PWM
18  # led = adafruit_rgbled.RGBLED(RED_LED, GREEN_LED, BLUE_LED, invert_pwm=True)
19  
20  
21  def wheel(pos):
22      # Input a value 0 to 255 to get a color value.
23      # The colours are a transition r - g - b - back to r.
24      if pos < 0 or pos > 255:
25          return 0, 0, 0
26      if pos < 85:
27          return int(255 - pos * 3), int(pos * 3), 0
28      if pos < 170:
29          pos -= 85
30          return 0, int(255 - pos * 3), int(pos * 3)
31      pos -= 170
32      return int(pos * 3), 0, int(255 - (pos * 3))
33  
34  
35  def rainbow_cycle(wait):
36      for i in range(255):
37          i = (i + 1) % 256
38          led.color = wheel(i)
39          time.sleep(wait)
40  
41  
42  while True:
43      # setting RGB LED color to RGB Tuples (R, G, B)
44      led.color = (255, 0, 0)
45      time.sleep(1)
46  
47      led.color = (0, 255, 0)
48      time.sleep(1)
49  
50      led.color = (0, 0, 255)
51      time.sleep(1)
52  
53      # setting RGB LED color to 24-bit integer values
54      led.color = 0xFF0000
55      time.sleep(1)
56  
57      led.color = 0x00FF00
58      time.sleep(1)
59  
60      led.color = 0x0000FF
61      time.sleep(1)
62  
63      # rainbow cycle the RGB LED
64      rainbow_cycle(0.1)