Stepper motor controlled by temperature sensor

Hello all,
I have been tinkering around with a fairly small stepper motor. I have my arduino running a temperature sensor, LCD, and hbridge for the bipolar (4 pin) stepper motor. The code I have runs the temperature sensor value every 2 seconds and has an if statement that will run the stepper motor at 78 rpm for a fixed amount of steps. My only problem is that I am doing all of this in the void loop, so it will run the command to have the motor run, but if the temp remains in the correct range it will run the loop over again.

if(temperatureF >= tempFStart)
myStepper.setSpeed(78); //motor travels at roughly 0.5 inches/4 seconds
myStepper.step(375); //motor turns 375 steps = 1.5 inches traveled
My question is how do I make it so the program will run through and activate the motor when it reaches a certain degree range and stop?

My other question is how can I make the motor stay where it is until the temperature sensor value goes back to within range? Can I make the motor return to 0 position?

Again, the segment of code I provided is within a void loop.

Any help or tips would be very much appreciated 8)

You need a "flag" that you test each time you look at the temperature.

Flag = false

If temp above trigger point and flag is false
Run motor
Set flag to true
Else if temp below trigger point
Set flag to false

This will run the motor for fixed number of steps as you state in the first paragraph.

However you later want it to run until the temperature goes back to a certain range. You can't have both at the same time.


Thank you very much for the suggestion. That was such a simple thing that I overlooked and it works great now!