@hbaxton
Take a look at this sketch. I reworked your sketch and put the motor running part into a function then, made it work with blink without delay style. It is untested but, I think it will work.
#include <NewPing.h>
#include <AFMotor.h>
#define TRIGGER_PIN 7 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 7 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
AF_Stepper motor(200, 1);
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
unsigned int pingSpeed = 1000; // How frequently are we going to send out a ping (in milliseconds). 50ms would be 20 times a second.
unsigned long pingTimer; // Holds the next ping time.
unsigned long motorTimer; // Holds the place for motor speed adjusts
unsigned int adjustTime = 1000; // how often to adjust the speed of the motor
int rpm =10;
void setup(){
Serial.begin(115200);
pingTimer = millis(); // Start now.
Serial.println("Stepper test!");
motor.setSpeed(100); // 100 rpm
motor.step(100, FORWARD, SINGLE);
Serial.println("step done");
motor.release();
delay(1000);
}
void loop(){
// Notice how there's no delays in this sketch to allow you to do other processing in-line while doing distance pings.
if (millis() >= pingTimer) // pingSpeed milliseconds since last ping, do another ping.
{
pingTimer = millis() + pingSpeed; // Set the next ping time.
sonar.ping_timer(echoCheck); // Send out the ping, calls "echoCheck" function every 24uS where you can check the ping status.
}
////////////////////////////////////////Here is the new part that will run your motor on a timer
if (millis() >= motorTimer)
{
motorrun();
motorTimer = millis() + adjustTime;
}
}
void motorrun()
{ // this is the function that will run your motor when called
Serial.print("setting RMP = ");
Serial.println(rpm);
motor.setSpeed(rpm);
Serial.println();
Serial.println();
motor.step(100, FORWARD, SINGLE);
rpm = rpm +10;
}
void echoCheck() { // Timer2 interrupt calls this function every 24uS where you can check the ping status.
// Don't do anything here!
if (sonar.check_timer()) { // This is how you check to see if the ping was received.
// Here's where you can add code.
Serial.print("Ping: ");
Serial.print(sonar.ping_result / US_ROUNDTRIP_CM); // Ping returned, uS result in ping_result, convert to cm with US_ROUNDTRIP_CM.
Serial.println("cm");
}
}