This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
en:iot-open:practical:hardware:sut:stm32:emb8_1 [2024/04/20 08:40] – created ktokarz | en:iot-open:practical:hardware:sut:stm32:emb8_1 [2024/04/20 09:46] (current) – [Steps] ktokarz | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== STM_8: Controlling Smart LED stripe ===== | ====== STM_8: Controlling Smart LED stripe ===== | ||
- | A Smart LED stripe is a chain of connected digital LEDs (also referenced as NEOPIXEL) which can be individually controlled. The stripe in our lab equipment consists of eight RGB LEDs. There exist also other configurations such as RGBWW (Red+Green+Blue+Warm White+Cold White) or WWA (Warm White+Cold White+Amber). They are controlled with just one pin/GPIO. GPIO sends the digital signal to the first LED in a chain and the LED passes data to the next one, and so on.\\ The most common type of LED stripes is WS2812B (RGB). Initially LED Stripes were powered with 5V, but that limits the length of the chain up to some 1-2m (because of the voltage drop), so nowadays LED stripes powered with 12V and even 24V are getting more and more popular.\\ \\ | + | A Smart LED stripe is a chain of connected digital LEDs (also referenced as NEOPIXEL) which can be individually controlled. The stripe in our lab equipment consists of eight RGB LEDs. There exist also other colour |
In this scenario, you will learn how to control a small LED RGB Stripe, composed of 8 Smart (Digital) LEDs with STM32 SoC. | In this scenario, you will learn how to control a small LED RGB Stripe, composed of 8 Smart (Digital) LEDs with STM32 SoC. | ||
+ | < | ||
+ | Sometimes such a chain of electronic elements is nicely called the Daisy Chain. | ||
+ | </ | ||
===== Prerequisites ===== | ===== Prerequisites ===== | ||
Line 36: | Line 39: | ||
Include necessary library: | Include necessary library: | ||
<code c> | <code c> | ||
- | #include "Freenove_WS2812_Lib_for_ESP32.h" | + | #include "Adafruit_NeoPixel.h" |
</ | </ | ||
Line 42: | 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 ==== |