Syntax:
void setLedInstance(std::shared_ptr<LED_Base> instance); Description:
Parameters:
Return:
Syntax:
LED_Base* getLedInstancePtr(void); Description:
Parameters:
Return:
Syntax:
bool begin(void); Description:
Parameters:
Return:
Syntax:
void display(void); Description:
Parameters:
Return:
Syntax:
void setAutoDisplay(bool enable); Description:
Parameters:
Return:
Syntax:
size_t getCount(void); Description:
Parameters:
Return:
Syntax:
RGBColor* getBuffer(void); Description:
Parameters:
Return:
Syntax:
void setBrightness(uint8_t brightness); Description:
Parameters:
Return:
Syntax 1:
void setColor(size_t index, const RGBColor& color); Syntax 2:
void setColor(size_t index, uint8_t red, uint8_t green, uint8_t blue); Syntax 3:
void setColor(size_t index, T c); Description:
Parameters:
Return:
Syntax:
void setColors(const T*s, size_t index = 0, size_t length = INT32_MAX); Description:
Parameters:
-s:
Return:
Syntax:
void setAllColor(T c); Description:
Parameters:
Return:
Syntax:
bool isEnabled(void); Description:
Parameters:
Return:
#include "M5Unified.h"
#include "utility/led/LED_Strip_Class.hpp"
#include "utility/led/LED_Base.hpp"
RGBColor colors[10] = {
{ 255, 0, 0 }, // Red
{ 0, 255, 0 }, // Green
{ 0, 0, 255 }, // Blue
{ 255, 255, 0 }, // Yellow
{ 0, 255, 255 }, // Cyan
{ 255, 0, 255 }, // Magenta
{ 128, 128, 128 }, // Gray
{ 255, 128, 0 }, // Orange
{ 0, 128, 255 }, // Sky Blue
{ 128, 0, 255 } // Purple-Blue
};
void setup() {
M5.begin();
// Configure RMT bus for LED strip (data pin: GPIO26)
auto busled = std::make_shared<m5::LedBus_RMT>();
auto buscfg = busled->getConfig();
buscfg.pin_data = 26;
busled->setConfig(buscfg);
// Configure LED strip (30 LEDs, 3 bytes/LED, GRB order)
auto led_strip = std::make_shared<m5::LED_Strip_Class>();
auto ledcfg = led_strip->getConfig();
ledcfg.led_count = 30;
ledcfg.byte_per_led = 3;
ledcfg.color_order = m5::LED_Strip_Class::config_t::color_order_grb;
led_strip->setConfig(ledcfg);
led_strip->setBus(busled); // Link bus to LED strip
M5.Led.setLedInstance(led_strip); // Register to M5 system
M5.Led.begin(); // Initialize LED strip
M5.Display.clear();
M5.Display.setFont(&fonts::FreeMonoBoldOblique12pt7b);
M5.Display.setCursor(20, 50);
M5.Display.printf("LED Cnt: %d", M5.Led.getCount());
M5.Display.setCursor(20, 70);
M5.Display.printf("LED Status: %s", M5.Led.isEnabled() ? "Enabled" : "Disabled");
M5.Led.setBrightness(100);
}
void loop() {
static int offset = 0; // Scrolling offset (persists between loops)
RGBColor* buf = M5.Led.getBuffer(); // Get LED color buffer
// Assign colors to each LED with offset (cyclic scrolling)
for (int i = 0; i < 30; ++i) {
buf[i] = colors[(i + offset) % 10];
}
M5.Led.setColors(buf, 0, 30); // Update LED strip with buffer data
offset = (offset + 1) % 10; // Increment offset (cycle 0-9)
}Using M5GO to run the above code, connect a 30-LED RGB strip to PORT.B, the effect is as follows: