Hi! Not that good with arduino yet.
I would want to control a a bunch of servo motors (around 7) with two push buttons.
If I press button 1 the servos will move on its own. If I press button 2 I can control the servos with potentiometers.
I tried using Interrupts but when I do, I can't control the servos manually.
Dkdderk:
Hi! Not that good with arduino yet.
...
I tried using Interrupts but when I do, I can't control the servos manually.
It's unlikely you need interrupts. Post your code (see the pinned thread 'How to use this forum' at the top of every topic), *enclosed in code tags * so somebody can see what you've got and maybe offer guidance.
Dkdderk:
If I press button 1 the servos will move on its own. If I press button 2 I can control the servos with potentiometers.
dougp is showing remarkable restraint not pointing OP at his (dougp's, not OP's) state machine tutorial.
As a matter of interest, what happens if neither or both button is pressed?
neiklot:
dougp is showing remarkable restraint not pointing OP at his (dougp's, not OP's) state machine tutorial.
Given the OP's minimal post I was leaning toward suggesting a possibly simpler if/else approach. But, without more information things are at a standstill.
neiklot:
As a matter of interest, what happens if neither or both button is pressed?
When neither is pressed, the servos go to a specific angle and stays in that position.
Selecting between modes can be done with a variable that keeps track of the selected mode. It could be a simple as a char variable that (in your case) takes any of three values 'F' for fixed positions, 'I' for independent movement and 'P' for potentiometer control.
The variable will change when the button is pressed.
Depending on the value of the variable the relevant function can be called - something like
if (modeVar == 'F') {
fixedPositionFunction();
}
else (if modeVar == 'I') {
independentMoveFunction();
}
else {
potentiometerMoveFunction();
}
You can make the code a bit neater and a bit less cryptic if you use an ENUM but the effect will be the same
...R