It also might be helpful to make a crude flow diagram to show exactly what behavior you want. Maybe even pseudocode. Sometimes writing it down in plain English can help you structure code better. Eg:
Check button 1
If pressed -> call this function.
else do nothing.
Check button 2
If pressed -> call this function.
else -> call this function.
I think its fairly clear what you want to do just from your code but there are some errors. I will try to point a few out:
..
void loop() {
curMillis = millis();
readButtons();
readButtons();
delay(analogRead(0) / 4 + 5)
if (i < 1) break;
}
This requires a semi-colon after "delay(analogRead(0) / 4 + 5)". Also, why are you trying to break out of the main loop? Surely you want this to run as a loop, with everything you need happening inside it.
A break in main will reset the micro back to the setup - this can work in some instances but isn't best practice.
void readButtons() {
buttonCCWpressed = false;
buttonCWpressed = false;
if (digitalRead(buttonCWpin) == LOW) {
buttonCWpressed = true;
}
if (digitalRead(buttonCCWpin) == LOW) {
buttonCCWpressed = true;
}
}
You set the boolean vars buttonXXXpressed when the buttons are pressed (active low) but you don't check these vars anywhere else in the code. All this does is set bits if a button is pressed - it doesn't act on it with anything else.
void actOnButtons()
if (buttonCWpressed == true) {
digitalWrite(directionPin, LOW);
singleStep();
}
if (buttonCCWpressed == true) {
digitalWrite(directionPin, HIGH);
singleStep();
}{ delay(analogRead(0) / 4 + 5);
i--;
if (i < 1) break;
}
This function is never called, so it will never change the pins or call "singlestep". Also you have an extra opening curly brace before "delay".
void singleStep() {
if (curMillis - prevStepMillis >= millisBetweenSteps) {
+= millisBetweenSteps;
prevStepMillis = curMillis;
digitalWrite(stepPin, HIGH);
digitalWrite(stepPin, LOW);
}
}
You're missing a var before " += millisBetweenSteps;" I can only assume you're adding this to something. Also, what happens if this function is called in less than 25ms between curMillis and prevStepMillis? It will check that >25ms has passed, but it hasn't so it won't change the step pin. That's fine, as it will just skip until more than 25ms has passed, but for now just use a simple delay of say 100ms. This means it will always cause a motor step, and will block, but for simplicity, its just to get it working.
All the above means it won't compile - the Arduino IDE will provide errors, and those errors will tell you which lines the problem(s) lie. A missed semicolon will flag up the line
after the missing semicolon, so you should look at the line before. Unfortunately it can also hide warnings such as "function never used" which can be handy to point out you're never actually calling a function you need.