This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:iot-open:practical:hardware:sut:stm32:emb8_1 [2024/04/20 08:42] – [STM_8: Controlling Smart LED stripe] ktokarz | en:iot-open:practical:hardware:sut:stm32:emb8_1 [2024/04/20 09:46] (current) – [Steps] ktokarz | ||
---|---|---|---|
Line 39: | Line 39: | ||
Include necessary library: | Include necessary library: | ||
<code c> | <code c> | ||
- | #include "Freenove_WS2812_Lib_for_ESP32.h" | + | #include "Adafruit_NeoPixel.h" |
</ | </ | ||
Line 45: | Line 45: | ||
Declare configuration and a controller class: | Declare configuration and a controller class: | ||
<code c> | <code c> | ||
- | # | + | # |
- | # | + | # |
- | #define WLEDS_CHANNEL | + | |
- | static Freenove_ESP32_WS2812 stripe = Freenove_ESP32_WS2812(WLEDS_COUNT, WLEDS_PIN, WLEDS_CHANNEL, | + | Adafruit_NeoPixel strip(NUMPIXELS, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800); |
</ | </ | ||
+ | The strip class definition contains the number of pixels, the pin for transmission, | ||
=== Step 3 === | === Step 3 === | ||
- | To switch a particular LED, use the following | + | To switch a particular LED, use the function |
<code c> | <code c> | ||
- | | + | void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b); |
- | | + | void setPixelColor(uint16_t n, uint32_t c); |
+ | </ | ||
+ | If you use the first version you give the LED number as the first parameter and then three colour values for red, green and blue colour intensity as the number in the 0-255 range.\\ | ||
+ | If you use the second version you give the LED number as the first parameter and a 32-bit version of the colour information. To convert three RGB bytes to 32-bit value you can use the function '' | ||
+ | <code c> | ||
+ | static uint32_t Color(uint8_t r, uint8_t g, uint8_t b); | ||
+ | </ | ||
+ | <note tip>Note that the LED number is 0-based, so in the case of our laboratory equipment, valid indexes are 0...7.</ | ||
+ | The '' | ||
+ | The different versions of the '' | ||
+ | <code c> | ||
+ | strip.setPixelColor(0, strip.Color(10, 0, 0)); // Red | ||
+ | strip.setPixelColor(1, | ||
+ | strip.setPixelColor(2, | ||
+ | strip.setPixelColor(3, | ||
+ | strip.show(); | ||
</ | </ | ||
- | Parameters are: '' | ||
- | <note tip>Note that the index is 0-based, so in the case of our device, valid indexes are 0...7.</ | ||
- | If you want to set all LEDs in the stripe to the same colour, there is a handy function: '' | ||
==== Result validation ==== | ==== Result validation ==== |