Connecting Three LEDs with Arduino
Circuit Diagram
See Also: Arduino Development Platform
Arduino Sketch
const int led1 = 2;
const int led2 = 3;
const int led3 = 4;
const int INTERVAL = 200; // 200 milli seconds interval
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}
void loop() {
// Switch-off all LEDs
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
delay(INTERVAL);
// Switch on LED1 for 200 milli seconds
digitalWrite(led1, HIGH);
delay(INTERVAL);
digitalWrite(led1, HIGH);
delay(INTERVAL);
// Switch on LED2 for 200 milli seconds
digitalWrite(led2, HIGH);
delay(INTERVAL);
digitalWrite(led2, HIGH);
delay(INTERVAL);
// Switch on LED3 for 200 milli seconds
digitalWrite(led3, HIGH);
delay(INTERVAL);
digitalWrite(led3, HIGH);
delay(INTERVAL);
}
No comments:
Post a Comment