We use Arduino UNO to control three LEDs by pushing the button
- Output: 3 pins for three LEDs
- Conditions
- Push off - Light on the yellow LED.
- Diagram Circuit
- Coding
int pushButton = 2;
int ledYellow = 3;
int ledGreen = 4;
int ledRed = 5;
int swichtState = 0;
void setup() {
pinMode(pushButton,INPUT);
pinMode(ledYellow, OUTPUT);
pinMode(ledGreen, OUTPUT);
pinMode(ledRed, OUTPUT);
}
void loop() {
swichtState = digitalRead(pushButton);
if(swichtState == 0){
digitalWrite(ledYellow,1);
digitalWrite(ledGreen,0);
digitalWrite(ledRed,0);
}else{
digitalWrite(ledYellow,0);
digitalWrite(ledGreen,0);
digitalWrite(ledRed,1);
delay(200);
digitalWrite(ledGreen,1);
digitalWrite(ledRed,0);e
delay(200);
}
}
No comments:
Post a Comment