Hi Guys,
I'm working on a multi file sketch that leverages millis() to avoid blocking.
- I have a HC-SR04 setup to stop a motor when something is within 20cm. If the object is removed, the motor starts back up.
- I have a the step motor (288BYJ-48 5V DC 2106018457) that kicks off if a button is pressed. The step motor will then turn 180 degrees which takes 3 seconds.
If the button is pressed to trigger the step motor, the function for the HC-SR04 doesn't trigger the other motor to stop if something gets in the way during the 3 seconds the step motor is running. Once the step motor finishes, the HC-SR04 is then able to stop the motor due to the blockage.
I'm wondering if this is what it is or is there a way to get both functions to operate independently? The millis (I.e. non blocking strategy) I implemented, doesn't seem to fix the issue. Suggestions?
distanceWithAdds.ino (1.5 KB)
HC_SR04_check.ino (1.1 KB)
HC_SR04_flash.ino (1.2 KB)
setup.ino (473 Bytes)
stepMotor.ino (393 Bytes)
Per Railroader's suggestion, I'll review this other post. My gut tells me that once the step motor kicks off, it takes over the Arduino until it finishes the instruction (3 seconds). A non blocking strategy isn't going to help me with my problem. I'll tinker with my code some more before I accept this.
Thank you.