Go Down

Topic: The routine of Arduino-Breathing light (Read 1 time) previous topic - next topic

burnIC_Crazy

Apr 03, 2014, 09:55 am Last Edit: Apr 03, 2014, 09:57 am by burnIC_Crazy Reason: 1
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/
:P :P :P :P :P :P :P :P :P :P :P


Code: [Select]

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
   
}

Go Up