# How to read temperature values while the stepper motor is moving (non-blocking))

**URL:** <https://forum.arduino.cc/t/how-to-read-temperature-values-while-the-stepper-motor-is-moving-non-blocking/1115846>\
**Category:** Programming\
**Created:** [April 16, 2023, 12:39pm UTC](https://forum.arduino.cc/t/how-to-read-temperature-values-while-the-stepper-motor-is-moving-non-blocking/1115846 "2023-04-16T12:39:09Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![gcjr](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gcjr/32/314015_2.png) [@gcjr](https://forum.arduino.cc/u/gcjr)\
**Post date:** [April 16, 2023, 3:04pm UTC](https://forum.arduino.cc/t/how-to-read-temperature-values-while-the-stepper-motor-is-moving-non-blocking/1115846/7 "2023-04-16T15:04:36Z")

</div>

what about something like

```cpp
int step;
unsigned long usecLst;

void loop ()
{
    if (step) {
        unsigned long usec = micros ();
        if (usec - usecLst >= stepSpeed) {
            usecLst = usec;

            if (LOW == digitalRead (stepPin))
                digitalWrite (stepPin, HIGH);
            else {
                digitalWrite (stepPin, LOW);
                step--;
            }
        }
    }

    // read temp values
    if (millis () - lastReading >= interval) {
        temperatureReadings ();
        lastReading = millis ();
    }

    // check if the user has entered any input
    if (Serial.available ()) {
        char buf [80];
        int n = Serial.readBytesUntil ('\n', buf, sizeof (buf)-1);
        buf [n] = '\0';

        if ('s' == buf [0]) {
            sscanf (buf, "s%d", &step);
            Serial.println (step);
        }
    }
}

```

---

_[View the full topic](https://forum.arduino.cc/t/how-to-read-temperature-values-while-the-stepper-motor-is-moving-non-blocking/1115846)._
