The routine of Arduino-Breathing light is to let LED change from black to bright and then change to black, which is like heartbeat.
Implementation principle :It mainly use the default function analogWrite which is provided by the Arduino and use different output of pulse width to change the luminance of LED.If the pulse width increase from small to big , the luminance of LED will increase gradually accordingly,otherwise will become darker gradually.Welcome to my form to see the video:
www.icstation.com/forum/
int ledPin1 = 3; // LED connected to digital pin 3
int val1 = 0; // variable to store the read value
void setup()
{
pinMode(ledPin1, OUTPUT); // sets the pin as output
}
int direction_led1 =0;
int delay_time = 50;
void loop()
{
if(val1 == 50) direction_led1 =1;
if(val1 == 0) direction_led1 = 0;
if(direction_led1) --val1;
else ++val1;
delay(20);
analogWrite(ledPin1, val1); // analogWrite values from 0 to 255
}