jgraber
Text C example in EasyC:

I have uploaded a zipfile with a text version of the Default program, next to the other default program examples.
If you would rather type than using dragon droppings, here is an example to get started.
The block program main() just calls main_c() which was converted to C-code, so put all your new code there.
I suggest download, unzip, open, check to see if it compiles, save as your_pgm_name, then modify as you will.
Quote 0 0
jgraber
Beyond Button Go:  in (easy) C,  similar thing works in RobotC I'm sure.

Tank2(), Arcade(2), JoysticktoMotor() etc are "ButtonGo" programming; while you are pushing a button/joystick, the motor does what you said,  when you let go of the controller, everything stops.   But there are a whole host of useful things you can do "Beyond Button-Go!"

Problem: Because we BESTies often use Servos for grippers,  one of the annoying things about using JoystickDigitalToServo() for grippers, is that the gripper is half closed at value 0 when you dont press any buttons,  you have to hold a button to open the gripper all the way to -127,  and hold another button to close the gripper all the way to 127.  It would be easier to use if you could press one button to open the gripper, and another to close the gripper, but you didn't have to hold the buttons down, just press and then it is ok to release.

Solution: Have a button save in a variable, what you want the servo position to be.  Then set the servo to that position.
In the local or global variables section, or just after the opening brace { of the main_c.c routine, but outside the while(1) loop, declare  variables:
Inside the while(1) loop,  do if test on buttons and save the servo position.  
Only the 3 lines that say //new  are new from the default program.  (plus I removed the JoystickDeadband commands to remove distractions)
Code:

void main_c ( void      
     { // Use this instead of main; put all text C code here
           int Gripper_position; //new
           while ( 1 ) // repeats forever
           { // next 3 lines are //new
                 if ( GetJoystickDigital ( Joy1 , B5 , Up ) ) { Gripper_position = -127; } //new
                 if ( GetJoystickDigital ( Joy1 , B5 , Down ) ) { Gripper_position = +127; } //new
                 SetServo( M4, Gripper_position ); //new
           // we now continue with our usual Default program
          // Arcade parms: 1, F/B stick, L/R stick, LMotor, RMotor, Linvert, Rinvert)
          Arcade2 ( Joy1, Stk2 , Stk1, M9, M2, NoInvert, NoInvert ) ; // Ch2 is forward/reverse and Ch1 is rotate left/right: Basically the right stick is a normal joystick
          // JoyTo parms: 1, joychan, motorport, invert
          JoystickToServo ( Joy1 , Stk3 , M5 , Invert ) ; // Servo in Port 5 controlled by Joystick channel 3 (Left Up/Down stick) inverted
          JoystickToMotor ( Joy1 , Stk4 , M6 , NoInvert ) ; // Motor in port 6 controlled by Joystick channel 4 (Left right/left stick)
    } // end repeat forever
} // end of main_c

Remember that the Default code has a bunch of Global #define  at the top, that make aliases like  Joy1=1, B4=4, Up=1, Down=2, M5=5 etc
Let me know what other kinds of tips you would like to see, or add your own.
Edited several times, trying to get rid of Emoji that show up after Up
Quote 0 0

Add a Website Forum to your website.