respiration.ino
The GIGA's PWM goes up to 16 bits: the breathing ramp becomes perfectly smooth, without the 8-bit "staircase". Frequency is set per pin, out of the audible band.
Hardware required
An Arduino Giga R1 board (STM32H747 dual-core M7 at 480 MHz + M4, 76 I/O pins, 2 DACs, FDCAN) powered over USB-C or 5-24 V. 1 LED + 330 Ω resistor on D3.
Wiring
LED anode on D3 through 330 Ω to GND. Pick a PWM pin (marked ~): D3 qualifies.
How it works
analogWriteResolution raises the channel resolution; the loop increments a float setpoint to smooth the ramp despite the hardware step. 19.5 kHz sidesteps driver whine. In the Arduino IDE, install the « Arduino Zephyr-based Boards » (or Mbed) platform, select « Arduino Giga R1 », then Upload. 3.3 V logic.
Going further
Two channels to mix two LEDs (additive tint mixing), or a power dimmer on a MOSFET.
respiration.ino
// Respiration sur D3 — analogWrite 16 bits sur la GIGA.
const int LED = D3;
float niveau = 0;
float sens = 1.0f;
void setup() {
analogWriteResolution(16); // 0..65535
analogWriteFrequency(LED, 19531); // ~19.5 kHz : hors audible
Serial.begin(115200);
}
void loop() {
niveau += sens;
if (niveau >= 65535.0f || niveau <= 0.0f) sens = -sens;
analogWrite(LED, (uint16_t)niveau);
delayMicroseconds(200);
}