Hello everyone,
I'm new to programming and I am having trouble with coding a button to control two servo motors for a project. I don't know if I'm doing right or not please I need help!!
My code is based off another one:
#include <Servo.h>
Servo servo1;
Servo servo2;
#define pushButtonPin 2
int pos = 0;
int pos2 = 0;
int buttonPushed =0;
Pleaseread the forum guidelines to see how to properly post code and some hints on how to get the most from this forum. You can go back and fix your original post by highlighting the code and clicking the </> in the menu bar.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) and you will see the problem. You have closed loop() and the rest of the code is outside of a function which is not legal.
As the @groundFungus and @anon87005993 mentioned, properly indenting your code using tools -> autoformat will reveal what is wrong. This is what it looks like after an autoformat.
Each function (setup() and loop() in this case) start swith a { and ends with a }; a } at the beginning of a line indicates the end of a function. @anon87005993 already indicated where your loop() ends.
So the rest of the code is outside a function which is not allowed.
Further, you should never have more than one } at the beginning of a line at the end of your code. So below indicates a problem.
...
...
delay(50); //
}
}
}
}
How useful your code is, is debatable at this stage. Why would you set buttonPushed 180x90 times to 0? And by the time you reach servo1.Write() and servo2.write(), pos and pos2 are both 0. I suspect that those actually should have been inside the for-loops.