pdf-icon

Arduino Quick Start

2. Devices & Examples

6. Applications

Unit PoE-P4 RGB LED

Unit PoE-P4 RGB LED example.

Example

Compilation Requirements

  • M5Stack Board Manager version >= 3.2.6
  • Development board option = M5UnitPoEP4
  • M5Unified library version >= 0.2.13
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
#include "M5Unified.h"

void setRGB(uint8_t r, uint8_t g, uint8_t b){
    uint8_t red = ~r;
    uint8_t green = ~g;
    uint8_t blue = ~b;
    analogWrite(17, red);
    analogWrite(15, green);
    analogWrite(16, blue);
}

void setup() {
    M5.begin();
    pinMode(15, OUTPUT);
    analogWriteResolution(15, 8);
    pinMode(16, OUTPUT);
    analogWriteResolution(16, 8);
    pinMode(17, OUTPUT);
    analogWriteResolution(17, 8);
}

void loop() {
    setRGB(255, 0, 0);// red
    delay(2000);
    setRGB(0, 255, 0);// green
    delay(2000);
    setRGB(0, 0, 255);// blue
    delay(2000);
}

The RGB LED on the Unit PoE-P4 is wired to GPIO pins 15, 16 and 17, and uses a common‑anode design. The example code inverts the colour values before writing them out; the sketch cycles through red, green and blue, holding each colour for two seconds.

On This Page