Hi everyone, as a newcomer I have few questions in my little project that I have been working on.
I have created a fairly simple code that controls my servo by 2 different buttons. When pressed one turn the servo left and one right. Problem is that my code works a little wrong. The servo turns only when the button is pressed down and I want it to make the movement once the button is pressed. Like if I press the button real quick, servo goes to certain position and comes back.
please edit your posting to use code tags, its all explained in the sticky thread.
Are your buttons wired to ground or Vcc?
Your code handles 3 button states, perhaps one of them is neither-button-pressed?
Do you really want the servo to go somewhere everytime the buttons aren't pressed?
Hello, the previous post should be more clear now.
Iirc the ground was wired to power ground in the arduino board, same as servo power ground.
It is mandatory that the servo returns to the middle position, once the gear is shifted. But with this code it feels little dodgy from time to time (interference occurs for unknown reason). I was hoping to find better alternatives to have the middle point as "home" state and by one button click force the servo to turn for example from 90 to 180 and back.
Now when button is pressed, servo turns to the correct position, when released it comes back.
I feel like I need a direction to go with this programming, MY first code to be honest.
One thing that I thought is that would there be a certain angle which after servo gets input to return to home.
I have not tested the movement yet, but for example if after turning 20 degrees, the gear has been shifted, would the arduino generate a feedback to allow returning to home state?
For what I understand is that arduino knows the state at which servo is at all times
Zoomkart thank you for that, code is basic but seems like it does the job quite well. I'll just add some code and second button for downshifting.
The calibration with delay time and angles will only be set correctly in field test, those should not be a problem.
Another thing is to code a flatshift function when upshifting, I quess it is just a digital output signal that runs a relay with given time delay (that also is to be set correct, maybe 10-40 milliseconds).
Can I just add line to void loop with command that turn one digital pin high once button is pressed?
Should not be a difficult job and sorry for all this questions, I maybe should just test it out