/* Button Led code
* Objective light up the buttons in the sequnece and actual elevator would move
* last edit done by oumer at 3:31 on 18/04/2024
if any changes note up here
*/
// constants won't change. They're used here to set pin numbers:
const int yellow_but = 2; // the number of the pushbutton pin
const int yellow_led = 13; // the number of the LED pin
const int green_but = 3; // the number of the pushbutton pin
const int green_led = 11; // the number of the LED pin
const int blue_but = 4; // the number of the pushbutton pin
const int blue_led = 12; // the number of the LED pin
const int red_but = 5; // the number of the pushbutton pin
const int red_led = 10; // the number of the LED pin
// intilzing the variables that will change later :
int y_buttonState = 0; // variable for reading the pushbutton status
int g_buttonState = 0; // variable for reading the pushbutton status
int b_buttonState = 0; // variable for reading the pushbutton status
int r_buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(yellow_led, OUTPUT);
pinMode(blue_led, OUTPUT);
pinMode(green_led, OUTPUT);
pinMode(red_led, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(yellow_but , INPUT);
pinMode(green_but , INPUT);
pinMode(blue_but , INPUT);
pinMode(red_but , INPUT);
}
void loop() {
// read the state of the pushbutton value:
y_buttonState = digitalRead(yellow_but);// equivalent on scanf but reads button input
g_buttonState = digitalRead(green_but);
b_buttonState = digitalRead(blue_but);
r_buttonState = digitalRead(red_but);
//Yellow LED
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (y_buttonState == HIGH) {
// turn LED on:
digitalWrite(yellow_led, HIGH);
delay(2000);// time delay that keeps the light on for 2 sec
} else {
// turn LED off:
digitalWrite(yellow_led, LOW);
}
// Green LED
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (g_buttonState == HIGH) {
// turn LED on:
digitalWrite(green_led, HIGH);
delay(2000);// time delay that keeps the light on for 2 sec
} else {
// turn LED off:
digitalWrite(green_led, LOW);
}
//Blue LED
// if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (b_buttonState == HIGH) {
// turn LED on:
digitalWrite(blue_led, HIGH);
delay(2000);// time delay that keeps the light on for 2 sec
} else {
// turn LED off:
digitalWrite(blue_led, LOW);
}
//Red LED
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (r_buttonState == HIGH) {
// turn LED on:
digitalWrite(red_led, HIGH);
delay(2000);// time delay that keeps the light on for 2 sec
} else {
// turn LED off:
digitalWrite(red_led, LOW);
}
}