const int ledPin = 9; // LED connected to digital pin 9
const int period = 5000; // Period of one breathing cycle in milliseconds
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
// Get the current time in the cycle
unsigned long currentTime = millis() % period;
// Calculate the brightness using a sinusoidal function
float brightness = (exp(sin(currentTime * M_PI / period)) - 0.36787944) * 108.0;
// Apply the calculated brightness to the LED
analogWrite(ledPin, (int)brightness);
// Small delay to smooth the breathing effect
delay(10);
}