ARDUINO UNO Project 02: Spaceship Interface

Ingredients :

1- LED – RED                      # 2

2- LED – GREEN                 # 1

3- Switch                             #1

4- Wire

5- Resistor   220Ω              #3

6- Resistor   10KΩ              #1

BUILD THE CIRCUIT

ARDUINO UNO Project 02: Spaceship Interface

ARDUINO UNO Project 02: Spaceship Interface

ARDUINO UNO Project 02: Spaceship Interface

 

 

Code:

int KeyState=0;
void setup() {
// put your setup code here, to run once:
pinMode(2, INPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
KeyState=digitalRead(2);
if (KeyState==0){
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
}else{
digitalWrite(3,LOW);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);

delay(250);

digitalWrite(4,LOW);
digitalWrite(5,HIGH);

delay(250);

}

}