Arduino Practice1

Aim : Through writing the Arduino code,I want to make two red lights blink automatically and the blue light blink by pressing the button on the breadboard.

Arduino code:

const int redled1=5;

const int redled2=4;

const int blueled=3;

 

const int switchPin=2;

 

void setup(){

pinMode(redled1,OUTPUT);

pinMode(redled1,OUTPUT);

pinMode(blueled,OUTPUT);

pinMode(switchPin,INPUT);

}

 

void loop(){

int switchState;

switchState=digitalRead(switchPin);

if(switchState==LOW){

 

digitalWrite(blueled,LOW);

digitalWrite(redled1,HIGH);

digitalWrite(redled2,LOW);

delay(250);

digitalWrite(redled1,LOW);

digitalWrite(redled2,HIGH);

delay(250);

}

else{

digitalWrite(redled1,LOW);

digitalWrite(redled2,LOW);

digitalWrite(blueled,HIGH);

}

}

 

Results: