Go Down

Topic: Connecting Arduino to Servos and Rotary Switch (Read 7536 times) previous topic - next topic

PaulS

Code: [Select]
void forward()

The name of this function is useless. It does NOT define what the function does. Good function names contain a noun and a verb. The noun defines what gets operated on. The verb describes the operation. digitalRead(), analogWrite(), etc. are good names. forward() is not.

Posting code that can actually compile is a good idea. Code that can actually compile includes a loop() function. All the actions for controlling your robot happen in loop(). Without seeing loop(), we have no clue why you can't (seem) to do what you want. It is certainly feasible. One thing to keep in mind is that it is impossible to press both switches at the same time. One WILL make contact (or be discovered to have made contact) before the other.

So, you need to NOT develop code that blocks if one switch is known to be pressed.  You need to deal with the case of switch one being pressed, and then switch two becoming pressed, and take different actions when both switches are pressed vs. when only one of the switches is pressed.
The art of getting good answers lies in asking good questions.

Go Up