Before we go any further let's try to describe all the "actions" that must happen for this project to work. For the moment don't worry about the order of things - just jot them down as they occur to you. For example ...
flash LEDa
flash LEDb
check the buttons
set the flashing period
ask the user for input
get the user's response
move the servo
read the potentiometer
set the servo position
Without noticing it we now have a huge part of the program designed. Let's make a separate function for each of those actions.
void flashLedA() {
}
void flashLedB() {
}
void checkButtons() {
}
void setFlashPeriod() {
}
void askForUserInput() {
}
void getUserResponse() {
}
void moveServo() {
}
void readPotentiometer() {
}
void setServoPosition() {
}
Of course at this stage none of these functions can do anything as they have no code within them - but we'll worry about that later.
Now, how would you go about using all those little functions? Let's try something very simple. What about this ...
void setup() {
}
void loop() {
flashLedA();
flashLedB();
checkButtons();
setFlashPeriod();
askForUserInput();
getUserResponse();
moveServo();
readPotentiometer();
setServoPosition();
}
Together with the earlier functions this is a complete Arduino sketch that will compile and run - even if it does nothing.
...