Hi,
I have having issues where the Arduino starts my program before waiting for the startCycle signal.
I am pretty new to writing like this, all my knowledge comes from writing PLC programs but it doesn't seem to function in the same way.
It also doesn't follow the cycle as intended even when it starts by itself.
Thank you in advance for all your help.
This is the intended cycle.
Step 0 -
startCycle input LOW
cycleStep = 0
Step 1 -
startCycle input HIGH
cycleStep = 1
turn cycleLed ON
Step 2 -
--------->it seems to start here and then just keeps the motor spinning without changing direction.
check if cycleStep = 1
motorDirection High
motorPulse High
increase pulseCount by 1
pause
motorPulse Low
check if pulseCount is equal to 200
if equal make cycleStep = 2
make pulseCount = 0
Step 3 -
check if cycleStep = 2
motorDirection Low
motorPulse High
increase pulseCount by 1
pause
motorPulse Low
check if pulseCount is equal to 200
if equal make cycleStep = 3
make pulseCount = 0
Step 4 -
check if cycleStep = 3
turn cycleComplete LED on and off
turn cycleLed OFF
make cycleStep = 0
------ CODE START -----
//INPUTS
const int startCycle = 1;
//OUTPUTS
const int motorPulse = 6;
const int motorDirection = 7;
const int cycleLed = 8;
const int cycleComplete = 9;
//Counters
int pulseCount = 0;
//Steps
int cycleStep = 0;
void setup() {
Serial.begin(9600);
pinMode(startCycle, INPUT);
digitalWrite(startCycle, LOW);
pinMode(motorPulse, OUTPUT);
pinMode(motorDirection, OUTPUT);
pinMode(cycleLed, OUTPUT);
pinMode(cycleComplete, OUTPUT);
}
void loop() {
if (startCycle == HIGH){
digitalWrite(cycleLed, HIGH);
cycleStep = 1;
}
if (cycleStep == 1){
digitalWrite(motorDirection, HIGH);
digitalWrite(motorPulse, HIGH);
pulseCount += 1;
delay(30);
digitalWrite(motorPulse, LOW);
if(pulseCount == 200){
cycleStep = 2;
pulseCount = 0;
}
}
if (cycleStep == 2){
digitalWrite(motorDirection, LOW);
digitalWrite(motorPulse, HIGH);
pulseCount += 1;
delay(30);
digitalWrite(motorPulse, LOW);
if(pulseCount == 200){
cycleStep = 3;
pulseCount = 0;
}
}
if (cycleStep == 3){
digitalWrite(cycleComplete, HIGH);
delay(1000);
digitalWrite(cycleComplete, LOW);
delay(1000);
digitalWrite(cycleComplete, HIGH);
delay(1000);
digitalWrite(cycleComplete, LOW);
delay(1000);
digitalWrite(cycleComplete, HIGH);
delay(1000);
digitalWrite(cycleComplete, LOW);
digitalWrite(cycleLed, LOW);
cycleStep = 0;
}
}
------ CODE STOP -----