0% found this document useful (0 votes)
77 views

3 LED 2 Push Button Arduino

This code defines pin assignments for three LED lights (red, yellow, green) and two push buttons. It sets the pin modes in setup() and uses the push buttons to increment or decrement a counter variable to cycle through the three LED colors in the loop().

Uploaded by

Veni Hârâzuku
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views

3 LED 2 Push Button Arduino

This code defines pin assignments for three LED lights (red, yellow, green) and two push buttons. It sets the pin modes in setup() and uses the push buttons to increment or decrement a counter variable to cycle through the three LED colors in the loop().

Uploaded by

Veni Hârâzuku
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

const int ledY = 12;

const int ledR = 11;


const int ledG = 10;
const int pb1 = 5;
const int pb2 = 6;
int hasilpb1;
int hasilpb2;
int j = 0;

void setup() {
pinMode(ledY,OUTPUT);
pinMode(ledR,OUTPUT);
pinMode(ledG,OUTPUT);
pinMode(pb1,INPUT);
pinMode(pb2,INPUT);

void loop() {
hasilpb1=digitalRead(pb1);
if(hasilpb1==1){
j++;
delay(300);
}
hasilpb2=digitalRead(pb2);
if(hasilpb2==1){
j--;
delay(300);
}

switch(j){
case 1:
digitalWrite(ledR,HIGH);
digitalWrite(ledY,LOW);
digitalWrite(ledG,LOW);
break;
case 2:
digitalWrite(ledR,LOW);
digitalWrite(ledY,HIGH);
digitalWrite(ledG,LOW);
break;
case 3:
digitalWrite(ledR,LOW);
digitalWrite(ledY,LOW);
digitalWrite(ledG,HIGH);
break;
default:
digitalWrite(ledR,LOW);
digitalWrite(ledY,LOW);
digitalWrite(ledG,LOW);
break;

}
}

You might also like