int redled =2;
int yellowled =4;
int greenled =6;
// the setup function runs once when
you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(2, OUTPUT); //For red LED
pinMode(4, OUTPUT); //For yellow LED
pinMode(6, OUTPUT); //For green LED
}
// the loop function runs over and
over again forever
void loop() {
digitalWrite(redled, HIGH); //
turn the red LED on
delay(2000);
// wait for a second
digitalWrite(redled, LOW); //
turn the red LED off
delay(2000);
// wait for a second
digitalWrite(yellowled, HIGH);
// turn the yellow LED on
delay(500);
// wait for 0.5 second
digitalWrite(yellowled, LOW);
// turn the yellow LED off
delay(500);
// wait for 0.5 second
digitalWrite(greenled, HIGH); //
turn the green LED on
delay(2000);
// wait for a second
digitalWrite(greenled, LOW); //
turn the green LED off
delay(2000);
// wait for a second
}
Result:
0 Comments