const int ledPin = LED_BUILTIN; // the number of the LED pin
int ledState = LOW; // ledState used to set the LED
// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long motor_read_time = 0; // will store last time LED was updated
unsigned long motor_last_stepped = 0;
const long read_interval = 1000; // interval at which to blink (milliseconds)
const long step_interval = 2000;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
// check to see if it's time to blink the LED; that is, if the difference
// between the current time and last time you blinked the LED is bigger than
// the interval at which you want to blink the LED.
// millis() will overrun after 50 days
unsigned long loop_time = millis();
// using while instead of if:
// https://forum.arduino.cc/t/demonstration-code-for-several-things-at-the-same-time/217158/32
// post 32
while (loop_time - motor_read_time >= read_interval) {
// save the last time you blinked the LED
motor_read_time += read_interval;
read_motor();
}
}
void read_motor(){
// if the LED is off turn it on and vice-versa:
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}