pdf-icon

Arduino Quick Start

2. Devices & Examples

6. Applications

PowerHub RGB LED

APIs and example programs related to PowerHub RGB LED.

Example Program

Compile Requirements

  • M5Stack board manager version >= 3.2.3
  • Board selection = M5PowerHub
  • M5Unified library version >= 0.2.11
cpp
1 2 3 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
#include <M5Unified.h>

void setup() {
  M5.begin();
  M5.Led.setBrightness(255);  // 0 ~ 255
}

void loop() {
  M5.update();

  // color enums, see: https://docs.m5stack.com/en/arduino/m5gfx/m5gfx_appendix#color%20encoding
  M5.Led.setAllColor(TFT_WHITE);
  M5.Led.display();
  delay(500);

  // r, g, b
  M5.Led.setAllColor(0, 0, 0);  // Black (off)
  M5.Led.display();
  delay(500);

  // index, r, g, b
  M5.Led.setColor(0, 255, 255, 255);  // White
  M5.Led.setColor(1,   0,   0,   0);  // Black (off)
  M5.Led.setColor(2, 255,   0,   0);  // Red
  M5.Led.setColor(3,   0, 255,   0);  // Green
  M5.Led.setColor(4,   0,   0, 255);  // Blue
  M5.Led.setColor(5, 255, 255,   0);  // Yellow
  M5.Led.setColor(6, 255,   0, 255);  // Magenta
  M5.Led.setColor(7,   0, 255, 255);  // Cyan
  M5.Led.display();
  delay(1000);
}

Running result:

API

The PowerHub RGB LED driver uses the Led_Class from the M5Unified library.

On This Page