Greetings to coding masters
I created the arduino code below and haven't found a solution.
Maybe someone is kind and can help me.
The problem that is unfinished and cannot be solved is in the last condition, namely the AFTER_LS1 condition. Where the command for "No action should occur if PB_forward is pressed" is not implemented so that when in this condition we press the PB_forward button the result remains active.
The scheme, components and process are as herebelow:
Description: An Arduino UNO connected to four push buttons (PB_stop, PB_reverse, PB_forward, PB_LS1) and two relays (relay_reverse, relay_forward). The initial state has all relays off.
Conditions:
REVERSE Condition:
If relay_forward is inactive,
When PB_reverse is pressed, activate relay_reverse.
No action should occur if PB_forward is pressed.
FORWARD Condition:
If relay_reverse is inactive,
When PB_forward is pressed, activate relay_forward.
No action should occur if PB_reverse is pressed.
STOP_ALL Condition:
When PB_stop is pressed, turn off both relay_reverse and relay_forward.
LS1 Condition:
If relay_forward is active,
When PB_LS1 is pressed, turn off relay_forward
AFTER_LS1 Condition:
If LS1 Condition was occured,
No action should occur if PB_forward is pressed.
// Pin Definitions
#define PB_reverse 2
#define PB_forward 3
#define PB_stop 4
#define PB_LS1 5
#define relay_reverse 6
#define relay_forward 7
// Variable Definitions
bool relay_reverse_active = false;
bool relay_forward_active = false;
bool LS1_condition_occurred = false;
void setup() {
// Initialize Serial Communication
Serial.begin(9600);
// Set Pin Modes
pinMode(PB_stop, INPUT);
pinMode(PB_reverse, INPUT);
pinMode(PB_forward, INPUT);
pinMode(PB_LS1, INPUT);
pinMode(relay_reverse, OUTPUT);
pinMode(relay_forward, OUTPUT);
}
void loop() {
// Check for PB_reverse Press
if (digitalRead(PB_reverse) == HIGH && !relay_forward_active) {
digitalWrite(relay_reverse, HIGH);
relay_reverse_active = true;
}
// Check for PB_forward Press
if (digitalRead(PB_forward) == HIGH && !relay_reverse_active) {
digitalWrite(relay_forward, HIGH);
relay_forward_active = true;
}
// Check for PB_stop Press
if (digitalRead(PB_stop) == HIGH) {
digitalWrite(relay_reverse, LOW);
digitalWrite(relay_forward, LOW);
relay_reverse_active = false;
relay_forward_active = false;
LS1_condition_occurred = false;
}
// Check for PB_LS1 Press
if (digitalRead(PB_LS1) == HIGH && relay_forward_active) {
digitalWrite(relay_forward, LOW);
LS1_condition_occurred = true;
}
// Check for PB_forward Press after LS1 Condition
if (digitalRead(PB_forward) == HIGH && LS1_condition_occurred) {
// No action should occur
}
}