Blinking an External LED with an Arduino
The above Schematic will guide you on how an External LED must be interfaced with an Arduino.
In the above case Two LED's red and yellow are connected.
you can use the same blink code which i have given in the previous post.Instead of using the pin number as 13 you can use the pin 9 and 10;
Any range of resistors between 1K and 10k can be used .
Code to use the above Schematic for blink as well as fading the LED's
int redled=9;
int yellowled=10;
void Setup()
{
pinMode(redled,OUTPUT);
pinMode(yellowled,OUTPUT);
}
void loop()
{
// For the blink of both the led
digitalWrite(redled,HIGH);
digitalWrite(yellowled,HIGH);
delay(1000);
digitalWrite(redled,LOW);
digitalWrite(yellowled,LOW);
delay(1000);
// For fading the LED
for(int i=0;i<250;i++)
{
analogWrite(redled,i);
analogWrite(yellowled,i);
}
for(int i=250;i<0;i--)
{
analogWrite(redled,i);
analogWrite(yellowled,i);
}
}//end of loop
Comment either use of code to test the fading and blink
The above Schematic will guide you on how an External LED must be interfaced with an Arduino.
In the above case Two LED's red and yellow are connected.
you can use the same blink code which i have given in the previous post.Instead of using the pin number as 13 you can use the pin 9 and 10;
Any range of resistors between 1K and 10k can be used .
Code to use the above Schematic for blink as well as fading the LED's
int redled=9;
int yellowled=10;
void Setup()
{
pinMode(redled,OUTPUT);
pinMode(yellowled,OUTPUT);
}
void loop()
{
// For the blink of both the led
digitalWrite(redled,HIGH);
digitalWrite(yellowled,HIGH);
delay(1000);
digitalWrite(redled,LOW);
digitalWrite(yellowled,LOW);
delay(1000);
// For fading the LED
for(int i=0;i<250;i++)
{
analogWrite(redled,i);
analogWrite(yellowled,i);
}
for(int i=250;i<0;i--)
{
analogWrite(redled,i);
analogWrite(yellowled,i);
}
}//end of loop
Comment either use of code to test the fading and blink
No comments:
Post a Comment