py32l020-i2c-rgb-led-pwm-5.ino
Controla un LED RGB a través de tres pines PWM para crear indicadores visuales dinámicos (respiración, parpadeo).
El M5Stamp Timer Power 2 tiene 5 IOs programables. Identifica cuáles soportan PWM (TIMER). El código usa analogWrite. Para un consumo mínimo, apaga los LEDs (0) durante las fases de sueño profundo.
py32l020-i2c-rgb-led-pwm-5.ino
/*
* M5Stamp Timer Power 2 (PY32L020) - RGB LED Control via PWM
* Platform: Arduino (PY32L020 Core)
* Note: On some M5Stamp variants, RGB LED is driven via dedicated pins or specific IO.
* This example assumes standard RGB LEDs on GPIOs supporting PWM (e.g., PA0, PA1, PA2)
*/
#include <Arduino.h>
// Define RGB LED Pins (Check M5Stamp Timer Power 2 Pinout: IOs 1-5 are programmable)
// Example mapping to IO1, IO2, IO3 which support PWM
#define LED_R_PIN PA0
#define LED_G_PIN PA1
#define LED_B_PIN PA2
void setRGB(int r, int g, int b) {
// Invert if Active Low (common on some modules)
// analogWrite expects 0-255
analogWrite(LED_R_PIN, 255 - r);
analogWrite(LED_G_PIN, 255 - g);
analogWrite(LED_B_PIN, 255 - b);
}
void setup() {
pinMode(LED_R_PIN, OUTPUT);
pinMode(LED_G_PIN, OUTPUT);
pinMode(LED_B_PIN, OUTPUT);
// Initialize Timer/PWM hardware if required by core (usually automatic with analogWrite)
setRGB(0, 0, 0);
delay(1000);
}
void loop() {
// Breathing effect Red (Low Power friendly if duty cycle is low)
for (int i = 0; i <= 255; i += 5) {
setRGB(i, 0, 0);
delay(10);
}
for (int i = 255; i >= 0; i -= 5) {
setRGB(i, 0, 0);
delay(10);
}
// Blink Green when System is 'Active'
setRGB(0, 0, 0);
delay(2000);
}