I’m on another arbitrary project I conjured up just to continue practicing the basics.
I’ve got my project wired up so that 3 successive LED’s strike. But after the 3rd I’d like my attached servo motor to move in a desired increment (not the popular sweeping situation).
Right now, the LED’s are working great but just the servo…not so much. Here is the code, which may not be very logical at this point after a few hours of tinkering with the code and trying anything I could think of -
When you post in this forum (or others), it's generally a good idea to state what the problem actually is. "This code doesn't do what I want" is useless unless you also tell us what it does AND what you want it to do.
I've got my project wired up so that 3 successive LED's strike. But after the 3rd I'd like my attached servo motor to move in a desired increment (not the popular sweeping situation).
I want the servo to move once the 3rd LED has illuminated.
Downtownmjb:
after the 3rd I'd like my attached servo motor to move in a desired increment (not the popular sweeping situation).
The initial position of the servo is undefined; I think you need to call myServo.write(pos); during setup, preferably before you call attach, to move it to its initial position.
If you intention is that the servo will move by 45 degrees each time the loop executes then you need to replace this:
myServo.write(prevPos + 45);
with something like this:
pos += 45;
myServo.write(pos);
After running this for a few seconds you will realise what the next problem is ...