RGB Led
A class to control RGB LEDs using the NeoPixel library.
Source code in wsd_esp32\rgb_led.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
__init__(pin, num_leds=1)
Initializes the RGB LED controller.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pin
|
int
|
The GPIO pin number to which the LED strip is connected. |
required |
num_leds
|
int
|
The number of LEDs in the strip. Default is 1. |
1
|
Source code in wsd_esp32\rgb_led.py
9 10 11 12 13 14 15 16 17 18 19 |
|
set_color(r, g, b)
Sets the color of all LEDs in the strip.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
r
|
int
|
The red component of the color (0-255). |
required |
g
|
int
|
The green component of the color (0-255). |
required |
b
|
int
|
The blue component of the color (0-255). |
required |
Source code in wsd_esp32\rgb_led.py
21 22 23 24 25 26 27 28 29 30 31 32 |
|
set_pixel(index, r, g, b)
Sets the color of a specific LED in the strip.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index
|
int
|
The index of the LED to set (0-based). |
required |
r
|
int
|
The red component of the color (0-255). |
required |
g
|
int
|
The green component of the color (0-255). |
required |
b
|
int
|
The blue component of the color (0-255). |
required |
Raises:
Type | Description |
---|---|
IndexError
|
If the index is out of range. |
Source code in wsd_esp32\rgb_led.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
set_brightness(brightness)
Adjusts the brightness of all LEDs in the strip.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
brightness
|
float
|
The brightness level (0.0 to 1.0). |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the brightness is not between 0.0 and 1.0. |
Source code in wsd_esp32\rgb_led.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
rainbow(delay)
Displays a rainbow animation on the LED strip.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
delay
|
float
|
The delay between frames in seconds. |
required |
Source code in wsd_esp32\rgb_led.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
wheel(pos)
Generates a color based on a position value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pos
|
int
|
The position value (0-255). |
required |
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple representing the RGB color (r, g, b). |
Source code in wsd_esp32\rgb_led.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
clear()
Turns off all LEDs in the strip by setting their color to black.
Source code in wsd_esp32\rgb_led.py
105 106 107 108 109 110 111 |
|