Stepper motor MOVES_STOP_MOVES

Hi!

I am currently working on a bit of code involving 2 temp gauges, lcd, relay, 1 stepper motor but it seems like the code around my for for statement pulsing the stepper drive causes som kind of delay making the stepper motor too move for 1 sec and then stop 1 sec and so on. I think I should need to run 2 loops simultaneously. Is there a way of doing this?

Best regards
Victor

you have a small bug at line 9 of your for loop... (at least as far as I can see :o )

:sweat_smile:

or isit at line 10...

demkat1:
or isit at line 10...

it depends if you start counting at line 0 or line 1.... :slight_smile:

void loop()

{
timesincestarts = millis(); //Counting millis to minutes
timesincestart= timesincestarts/ minute;

Serial.println(timesincestart);
//Button

reading = digitalRead(inPin); //Reading the value of the button and setting reading

// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
if (state == HIGH)
state = LOW;
else
state = HIGH;
time = millis();

}

if(state == HIGH)
{

//Tempmätare Serial

uint16_t rtd = max.readRTD();

float ratio = rtd;
ratio /= 32768;
Serial.print("Temperature = "); Serial.println(max.temperature(RNOMINAL, RREF)); //Writing Temperatur c value on second line of serial monitor
TempC = max.temperature(RNOMINAL, RREF);

//Tempgauge 2

sensors.requestTemperatures(); //Get temp
TempC2 = sensors.getTempCByIndex(0); //Turning it to degres

//The different sequences

if(0 <= timesincestart && timesincestart < sequence1 )
{
Settemp = temp1;
Setspeed = speed1;
currentsequence = 1;
}
if(sequence1 < timesincestart && timesincestart < (sequence2 + sequence1))
{
Settemp = temp2;
Setspeed = speed2;
currentsequence = 2;
}

if((sequence2 + sequence1) < timesincestart && timesincestart < (sequence3 + sequence2 + sequence1))
{
Settemp = temp3;
Setspeed = speed3;
currentsequence = 3;
}

if((sequence3 + sequence2 + sequence1) < timesincestart && timesincestart < (sequence4 + sequence3 + sequence2 + sequence1))
{
Settemp = temp4;
Setspeed = speed4;
currentsequence = 4;
}

if((sequence4 + sequence3 + sequence2 + sequence1) < timesincestart && timesincestart < (sequence5 + sequence4 + sequence3 + sequence2 + sequence1))
{
Settemp = temp5;
Setspeed = speed5;
currentsequence = 5;
}

if((sequence5 + sequence4 + sequence3 + sequence2 + sequence1) < timesincestart && timesincestart < (sequence6 + sequence5 + sequence4 + sequence3 + sequence2 + sequence1))
{
Settemp = temp6;
Setspeed = speed6;
currentsequence = 6;
}

if((sequence6 + sequence5 + sequence4 + sequence3 + sequence2 + sequence1) < timesincestart && timesincestart > (sequence7 + sequence6 + sequence5 + sequence4 + sequence3 + sequence2 + sequence1))
{
Settemp = speed7;
Setspeed = speed7;
currentsequence = 7;
}

if((sequence7 + sequence6 + sequence5 + sequence4 + sequence3 + sequence2 + sequence1) < timesincestart && timesincestart < (sequence8 + sequence7 + sequence6 + sequence5 + sequence4 + sequence3 + sequence2 + sequence1))
{
Settemp = temp8;
Setspeed = speed8;
currentsequence = 8;
}

if(sequence8 < timesincestart) //Timear den ut så når den inte setcurrent

{
previous = HIGH;
state = LOW;
currentsequence = 9;
}

else
{}

//Count

Setspeedcalc = 3/(10*Setspeed+1);

//Seriall Monitor

lcd.clear();
lcd.setCursor (0,0);
lcd.print("Sequence");
lcd.setCursor(9,0);
lcd.print(currentsequence);
lcd.setCursor(0,1);
lcd.print("Temp:");
lcd.print(TempC);
lcd.setCursor(8,1);
lcd.print("RPM:");
lcd.print(Setspeed);

//Motor kontroll

digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < stepsPerRevolution; x++) {
digitalWrite(stepPin,HIGH);
digitalWrite(stepPin,LOW);
delay(Setspeedcalc);

}
//if sats

if (TempC < Settemp && TempC != -247) { //Relay control with failsafe
analogWrite(relaych1, 1);
Serial.println("YES"); //diagnotsik
}

if (TempC > Settemp) {
analogWrite(relaych1, 0);
Serial.println("NO"); //diagnostik
}

//Nollställa värden

sensorValue = 0; // återställer värdet innan nästa loop
}

else if(currentsequence == 9)

{
digitalWrite(relaych1, 0);
lcd.clear();
lcd.setCursor (0,0);
lcd.print("Finish!");

}

previous = reading;

}

To make it easy for people to help you please modify your post and use the code button </>
codeButton.png

so your code looks like this and is easy to copy to a text editor. See How to use the Forum

Your code is too long for me to study quickly without copying to my text editor. The text editor shows line numbers, identifies matching brackets and allows me to search for things like all instances of a particular variable or function.

Also please use the AutoFormat tool to indent your code for easier reading.

A FOR loop may indeed interfere with the progress of the program. Use IF and allow loop() to do the iteration.

...R

Several Things at a Time

Stepper Motor Basics
Simple Stepper Code