Good evening all,
I'm new to programming and electronics and I am working on an app controlled car with a grab attachment using the 1sheeld gamepad.
I am trying to work out two separate parts of the code.
The first part is for the steering control, I would like the steering servo to move while the left or right buttons are held and to return to centre when they are released.
The second part is for the grab, I would like this to move until the button is released. I'll be using the coloured buttons for this part.
So far, I have only managed to get the servo to move to pre- determined angles using the code below. Please can you assist with this.
Please edit the post and place the code text inside code tags.
How does the behaviour of the program you posted, differ from what you want it to do? It does claim to do something that looks like button controlled steering.
At the moment it just moves directly to 0, 90, or 180 degrees. I want it to stop at any point when I release the button. For example, when the grab has sufficent pressure I'll left go of the button and it will stay there.
For the steering part I would like it to return to centre when released.
You didn't say that in the beginning. I suggest you catch up and post a complete description of all the desired actions.
The grab? Okay. NM.
You can't code directly for that, because there is no feedback to the MCU on the actual servo position. The only way to do that, is to move it in small steps.
while (servo end position has not been reached) and (grab button is active)
{
move servo one small step
delay
}