Better way to program the driver control?

Is there a better way to program the driver control besides having a while loop with a bunch of ifs asking if a button is pressed?


I am not sure which programming language you are using, but ROBOTC supports multi-tasking. We actually created a task for each type of control (DriveControl, FourBarControl, etc.) and simply start all the tasks just before the while-loop. We don’t have any code inside the while-loop, and ROBOTC actually thinks it’s a programmer error. :rolleyes:

Now, still this isn’t really what you are looking for because we still have a whole bunch of if-statements for the buttons. Technically you could do the following:

Let’s say you want Motor1 to run clockwise when button 6U is pressed, and counter-clockwise when 6D is pressed, stopping when neither are being pressed. Instead of a bunch of if and else-if statements, you could simply do:

  motor[port1] = (vexRT[Btn6U] *127) + (vexRT[Btn6D] * -127)

NOTE: This is assuming that the buttons return a value of 1 when pressed, and 0 when they are not. (I actually don’t know if the buttons return 127 or 1, I would assume it is 1.)

There are simple little things you can do like this for many different cases, and if you have any specific cases you would like to make simpler code for, I would be happy to help you.


Thanks for your help and information. We are using easy C. I have too big of a loop and I want a better response time.


I use EasyC V4 with one (astronomically huge) central loop running for driver control. With the old PIC controllers I did have some problems with poor response time. Not with the Cortex however.

If you feel that your central loop is running too slowly, try using a timer to determine how many times the loop runs per second (Hz).

Things that can bog down your bandwidth are: LCD screens, Print To Screen or Graphic Display statements, Ultrasonic Sensors and obviously wait statements.

Ps. Sometimes using multiple if statements is the only way to go.