ok here it is goes with more details....
before i begin let me say this, im not a programmer nor have a diploma on computer sciences, im an electrical enginner that likes to play with arduino to solve some issues at work, i THINK my issue is coming from the use of IF COMMANDS, every comment will be appreciated as long as you do it with the intend of helping, they help me grow on something i dont know much about
here is an example of a timer... the input voltage is 110v so im using a relay to turn it on, it has an output which is gingto arduino, that signal is 5v or 0v so im handling it as HIGH or LOW
the machine has two ways to be operated,
FIRST ONE..MANUAL
, i press one button, the gas spring will go down (no matter of timer, cause it is not being activated)
i press another button and the gas spring will go up (again no matter of timer)
SECOND WAY TO HANDLE IT ´AUTOMATIC´ (THIS IS THE ONE GIVING ME ISSUES)
1- i press two buttons at the same time, the relay #1 (this relay sends the voltage to the timer) once the timer turns on, it will start counting down (depending on how many seconds i set it, i can set up to 12seconds)... while it is counting down it will turn on the relay #3 (this relay activates a solenoid, this solenoid valve moves the spring down).
2- when the timer stops, it sends a 5v signal to arduino, when arduino gets this signal, it will turn off the relay #3, thenit will turn on relay #2 (this relay activates the second timer), while the second timer is counting down, it will activate the relay #4 (this activates the solenoid vavle to move the gas spring up).
3- when the second timer stops, it will send a 5v signal to arduino,when it gets the signal it will turn off all the relays or at least make sure they are off.
4- it needs to wait until i press the two buttons again to repeat the cycle
MY SPECIFIC QUESTION IS THIS:
WHEN I PRESS THE 2 BUTTONS THE RELAYS ARE ACTIVATED CORRECTLY, HOWEVER IF I PRESS THE BUTTONS AGAIN, IT WILL TURN ON THE RELAYS AGAIN (OBVIOUSLY CAUSE THE IF VALUE IS BEING MET)
NOW, HOW CAN I AVOID THAT FROM HAPPENING? IS THERE A WAY THAT IF I PRESS THE BUTTONS IT WILL START DOING THE PROGRAM AND NOT BEING INTERRUPTEDBY THE BUTTONS AGAIN?
NOTE: I LEARNED SOMEWHERE THAT I CAN USE A NOINTERRUPTS COMMAND SO NOTHING WILL STOP IT (NOT SURE HOW IT WORKS) HOWEVER THAT DOES NOT HELP ME, CAUSE IN THE FUTURE I HAVE TO WRITE A STOP COMMAND, SO IF THERE IS AN EMERGENCY, I CAN PRESS AN EMERGENCY BUTTON AND THE MACHINE NEEDS TO STOP AT ANY POINT OF THE PROGRAM
here is my code so far:
const int botonI = 13; // THESE FIRSTS TWO BUTTONS NEED TO BE PRESSED ON AUTOMATIC SECTION
const int botonD = 12;
const int botonLI = 11; //moves spring up
const int botonLD = 10; // moves spring down
const int Relay4 = 1; // ACTIVATES SOLENOID TO MOVE SPRING UP
const int Relay3 = 2; // ACTIVATES SOLENOID TO MOVE SPRING DOWN
const int Relay2 = 3; // ACTIVATES SECOND TIMER
const int Relay1 = 4; // ACTIVATES FIRST TIMER
const int Timer = 9; //THIS IS THE 5V SIGNAL FROM THE FIRST TIMER
const int Timer2 = 7; //THIS IS THE 5V SIGNAL FROM THE SECOND TIMER
const int Proceso = A0; //HERE I SELECT MANUAL OR AUTOMATIC
//FIN VARIABLE FISICAS*******************
int buttonState = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int timerState = 0;
int timerState2 = 0;
int relay1 = 0;
int relay2 = 0;
int relay3 = 0;
int relay4 = 0;
int proceso = 0;
//FIN VARIABLES INTERNAS******************
void setup() {
pinMode(Relay1, OUTPUT);
pinMode(Relay2, OUTPUT);
pinMode(Relay3, OUTPUT);
pinMode(Relay4, OUTPUT);
pinMode(botonD, INPUT);
pinMode(botonI, INPUT);
pinMode(botonLD, INPUT);
pinMode(botonLI, INPUT);
pinMode(Barrera, INPUT);
pinMode(Timer, INPUT);
pinMode(Timer2, INPUT);
pinMode(Proceso, INPUT);
}
//***********FIN SETUP
void loop(){
proceso = digitalRead(Proceso);
if (proceso == HIGH) {
AUTO();
}
else {
MANUAL();
}
STOP();
}
//*******************************************************************************
void MANUAL () {
buttonState3 = digitalRead(botonLD);
buttonState4 = digitalRead(botonLI);
if (buttonState3 == LOW) {
digitalWrite(Relay3, HIGH);
}
else {
digitalWrite(Relay3, LOW);
}
if (buttonState4 == LOW) {
digitalWrite(Relay4, HIGH);
}
else {
digitalWrite(Relay4, LOW);
}
}
//*****************************************************************************
void AUTO() {
buttonState = digitalRead(botonD);
buttonState2 = digitalRead(botonI);
timerState = digitalRead(Timer);
timerState2 = digitalRead(Timer2);
relay1= digitalRead(Relay1);
relay2 = digitalRead(Relay2);
relay3 = digitalRead(Relay3);
relay4 = digitalRead(Relay4);
if (buttonState == LOW && buttonState2 == LOW) {
digitalWrite(Relay3, HIGH);
digitalWrite(Relay1, HIGH);
}
if (timerState == HIGH && relay1 == HIGH) {
digitalWrite(Relay3, LOW);
digitalWrite(Relay2, HIGH);
digitalWrite(Relay4, HIGH);
}
if (timerState2 == HIGH && relay1 == HIGH && relay4 == HIGH) {
digitalWrite(Relay1, LOW);
digitalWrite(Relay3, LOW);
digitalWrite(Relay2, LOW);
digitalWrite(Relay4, LOW);
}
}