Servo Programming

Hello my team is competing in the BEST robotics competition. We are trying to program a servo to control a latch and to make it so you press a button and the servo will go to that degree and stay there, not go back to home once you let go of said button. How would this be done using EasyC version V4.

1.Make a Variable
2.Get the Joystick digital (Button) and assign it to the variable
3.If variable is true, then set servo

Good Luck

The servo did a twitching thing when we added the set servo. The code was…
#Include “Main.h”

void main ( void)
while ( 1 )
JoystickDigitalToServo ( 1 . 5 . 1. latchclose . 2. -127 . 2 ) :
if ( 1 )
SetServo ( latchclose . 127 ) :

Replace JoystickDigitaltoServo with GetJoystickDigital. It’s towards the bottom of the joystick functions.

I have another question… How do you make a servo go in steps? Say everytime you press a button the servo moves a certain degree.

Unique buttons or the same button?

Same button that moves the servo say 15 degrees… Each time you press that button the servo will move 15 degrees.

It would look something like this.

if ( JoyButton == Pressed && JoyButtonLast == NotPressed) {
ServoAngle +=15; //Add 15 Units

JoyButtonLast = JoyButton; //Save old button state

if (ServoAngle < 127){
SetServo(1,ServoAngle); //Update Servo