Good morning everyone,
I'm getting crazy with some issues about the code on my Arduino Uno. I'm a newbie and to me, it looks fine, I don't see any problem, but now I explain everything.
I need to manage a 24V motor through some 5V relays, just to move a platform forward/ backward. I have also 2 micros, one for the "maximum forward position reached" and one for the "maximum backward position reached".
The cycle starts when DI3 is HIGH and to manage the cycle I choose to use the logic by step, using the "switch...case" function.
Basically, when I perform a case, at the end of each one I increase the step.
My problem is that when I force the DI3 making a bridge with the Arduino 5V, nothing happens. Through the monitoring the value of STEP is always 0.
Am I doing something wrong?
Thank you.
#define ON LOW
#define OFF HIGH
// I/O
int Start = 3;
int MaxFwd = 5;
int MaxBkw = 6;
int MoveFwd = 8;
int MoveBkw = 9;
// VARIABLES
const int Step_0 = 0;
const int Step_10 = 10;
const int Step_20 = 20;
const int Step_30 = 30;
const int Step_999 = 999;
int STEP = 0;
void setup() //DEFINITION ---------------------------------------------------------------------------------------------------------------------------
{
//start serial connection
Serial.begin(9600);
//configure pins as inputs and outputs
pinMode(Start, INPUT);
pinMode(MaxFwd, INPUT);
pinMode(MaxBkw, INPUT);
pinMode(MoveFwd, OUTPUT);
pinMode(MoveBkw, OUTPUT);
}
void loop() // CYCLE -----------------------------------------------------------------------------------------------------------------------------------
{
Serial.print(STEP, DEC); //To show actual value of the STEP
delay(1000); //Only for test checking
switch (STEP)
{
case Step_0: // Start cycle --------------------------------------------------------------------------------------
if (digitalRead(Start) == HIGH) int STEP = 10; //Increase step
break;
case Step_10: // Forward --------------------------------------------------------------------------------------------
digitalWrite(MoveFwd, ON); //Cmd forward ON
if (digitalRead(MaxFwd) == HIGH) //Max forward reached
{
digitalWrite(MoveFwd, OFF); //Cmd forward OFF
int STEP = 20; //Increase step
}
break;
case Step_20: // Delay ---------------------------------------------------------------------------------------------
{
delay(5000); //Delay move
int STEP = 30; //Increase step
}
break;
case Step_30: // Backward ------------------------------------------------------------------------------------------
digitalWrite(MoveBkw, ON); //Cmd back ON
if (digitalRead(MaxBkw) == HIGH) //Max backward reached
{
digitalWrite(MoveBkw, OFF); //Cmd back OFF
int STEP = 999; //Increase step
}
break;
case Step_999: // End cycle ---------------------------------------------------------------------------------------------
{
delay(500); //Delay reset
int STEP = 0; //Reset step
}
break;
default:
int STEP = 0; //Reset step
break;
}
}