Interrupt or anything else ? ( Noobie )

Hello,

I have Mega2560. In my project, i have step motors and 2 sensors. Below is the codes’ body diagram

void setup(){

}

void loop() {

steppers();
readings();

}

void steppers(){

}

void readings(){

}

My problem is “steppers()” working around 60 second and then i can read sensors in “readins()”
I need to read sensors values from begining to the end of the program. I use analog pins to read sensors values.

Any idea, suggestion ? Maybe interrupt but it is complex to me using it on mega2560 with analogpins ?

Thank you

Are you, by any chance, making extensive use of "delay()" ?

(I only ask because you didn't actually post any code)

Any idea, suggestion ?

Use millis() for timing. See Several things at the same time

void loop() {

steppers();
readings();

}

Aside from the meaningless names for the functions, I have to wonder why you would diddle with the stepper motors and THEN read what information is needed to know how to diddle with the stepper motors.

With Arduinos, interrupts are rarely needed and should not be used by anyone except experts.
Interrupt Service Routines can be challenging to debug for various reasons, including that Serial.print(...) and delay(...) should not be used.

Interrupts are needed only when very fast response times are needed (say, microseconds) and are not needed for buttons pressed by humans or for something operating at "60 second" (60 times per second?). Study and learn the Blink Without Delay (BWOD) example.

What everyone else said: read "several things at the same time". If you are using a stepper library that "blocks", you need a non-blocking version.

So you leave out the most important part of your code :wink: Show us steppers() and readings(); actually, show us your complete code if you want any proper advise.