Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot-open:practical:hardware:sut:stm32:emb8_1 [2024/04/20 08:42] – [STM_8: Controlling Smart LED stripe] ktokarzen: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"
 </code> </code>
  
Line 45: Line 45:
 Declare configuration and a controller class: Declare configuration and a controller class:
 <code c> <code c>
-#define WLEDS_COUNT    8 +#define NEOPIXEL_PIN D8  //Arduino numbering D8, STM numbering PC_12 
-#define WLEDS_PIN     34 +#define NUMPIXELS 8      //How many LEDs are attached
-#define WLEDS_CHANNEL  0+
  
-static Freenove_ESP32_WS2812 stripe = Freenove_ESP32_WS2812(WLEDS_COUNTWLEDS_PINWLEDS_CHANNEL, TYPE_GRB);+Adafruit_NeoPixel strip(NUMPIXELSNEOPIXEL_PINNEO_GRB + NEO_KHZ800);
 </code> </code>
 +The strip class definition contains the number of pixels, the pin for transmission, and the type of LEDs. In our laboratory LEDs use Green Red Blue format of data and 800kHz data transmission frequency.
 === Step 3 === === Step 3 ===
-To switch a particular LED, use the following function:+To switch a particular LED, use the function ''setPixelColor();''. It accepts parameters of different types.
 <code c> <code c>
-  stripe.setLedColorData(1,60,0,0); //light Red of the 2nd LED +void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b); 
-  stripe.show(); //Writes colours to the LED stripe+void setPixelColor(uint16_t n, uint32_t c); 
 +</code> 
 +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 ''Color();'': 
 +<code c> 
 +static uint32_t Color(uint8_t r, uint8_t g, uint8_t b); 
 +</code> 
 +<note tip>Note that the LED number is 0-based, so in the case of our laboratory equipment, valid indexes are 0...7.</note> 
 +The ''setPixelColor();'' sets the appropriate data in the internal buffer of the class object. Sending it to the LED stripe requires the usage of the ''show();'' function afterwards.\\ 
 +The different versions of the ''setPixelColor();'' function can look like in the following code: 
 +<code c> 
 +strip.setPixelColor(0strip.Color(10, 0, 0)); // Red 
 +strip.setPixelColor(1, 0, 10, 0);              // Green 
 +strip.setPixelColor(2, 0, 0, 10);              // Blue 
 +strip.setPixelColor(3, 0x000F0F0F);            // White 
 +strip.show();                           // Update strip 
 </code> </code>
-Parameters are: ''setLedColorData(int index, u8 r, u8 g, u8 b);''.\\ 
-<note tip>Note that the index is 0-based, so in the case of our device, valid indexes are 0...7.</note> 
  
-If you want to set all LEDs in the stripe to the same colour, there is a handy function: ''setAllLedsColorData(u8 r, u8 g, u8 b);''. \\ Remember to use the ''show();'' function afterwards. 
  
 ==== Result validation ==== ==== Result validation ====
en/iot-open/practical/hardware/sut/stm32/emb8_1.1713602574.txt.gz · Last modified: 2024/04/20 08:42 by ktokarz
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0