const int LED_GREEN = 13; //Giving Pin 13 the name of LED_GREEN
const int BTN_GO = 2; //Giving Pin 2 the name of BTN_ON
const int LED_RED = 12; //Giving Pin 12 the name of LED_RED
const int BTN_STOP = 4; //Giving Pin 4 the name of BTN_OFF
const int BTN_RESET = 7;
int btn_state1 = 0; //Declaring the Button State variable
int btn_state2 = 0;
int btn_state3 =0;
void setup() {
// put your setup code here, to run once:
pinMode(LED_GREEN, OUTPUT); //Setting Pin 13 as an OUTPUT
pinMode(BTN_GO, INPUT); //Setting Pin 2 as an INPUT
pinMode(LED_RED, OUTPUT); //Setting Pin 12 as an OUTPUT
pinMode(BTN_STOP, INPUT);
pinMode(BTN_RESET, INPUT);
digitalWrite(BTN_GO, HIGH);
digitalWrite(BTN_STOP, HIGH);
digitalWrite(BTN_RESET, HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
btn_state1 = digitalRead(BTN_GO);
btn_state2 = digitalRead(BTN_STOP);
btn_state3 = digitalRead(BTN_RESET);
//Once button has been pressed LED stays ON
if (btn_state1 == LOW)
{
digitalWrite(LED_GREEN, HIGH);
digitalWrite(LED_RED, LOW);
}
if (btn_state2 == LOW){
digitalWrite(LED_GREEN, LOW);
digitalWrite(LED_RED, HIGH);
}
if (btn_state3 == LOW)
{
digitalWrite(LED_GREEN, LOW);
digitalWrite(LED_RED, LOW);
}
}
Comments