Stuck - Please Help

ac5ff:
Okay - I'm a complete nOOb with programming - at least since high school some 20+yrs ago! HA!
For whatever reason what I want to do sounds simple but I just cannot wrap my brain around it and haven't been able to get it to work.

I'm running a stepper motor CCW until it trips a switch (pin8). Once at that position I want to rotate CW 10 steps. And this needs to happen once at the start of the program. Once that is done it will not need to be done again unless the program restarts. Although I will probably write in a resetbutton switch that will force the program to re-run that section of code.

Simple; I think it is.. But why can I not seem to understand getting it to work?

Anyone have any ideas? Pointers? Sample code?!? LOL

thanks!

uint8_t motorHome; // C clears the vars to zero each time program starts

if (motorHome == 0) { // if var is zero then motor was not zeroed yet
    // rotate motor to limit switch
    motorHome = 1; // flag "motor is homed"
}

See what happens here?

When your sketch first starts (or you press reset and restart the sketch), C startup clears all vars to zero.

Therefore, if "motorHome" is zero, you know the stepper has not yet been "homed" in this reboot.

After you home / calibrate the stepper, you set "motorHome" to 1 and it stays that way until you restart the Arduino.

So, by checking if "motorHome" is 0 or 1, you know if your stepper is calibrated already or if you need to do it now.

Hope this helps.