Skip to content

Instantly share code, notes, and snippets.

@jimmyli97
Created December 11, 2014 05:34
Show Gist options
  • Save jimmyli97/41b9d23f61e09fd2a2fd to your computer and use it in GitHub Desktop.
Save jimmyli97/41b9d23f61e09fd2a2fd to your computer and use it in GitHub Desktop.
//Recall that Robotc stores the list of motors as the following:
typedef enum tMotor {
leftMotor = 0,
rightMotor = 7,
centerMotor = 1,
} tMotor;
//We can keep track of the number of motors using a constant that is updated by hand
#define NUM_MOTORS 3
//We can then create an array that we loop through to get all motors
tMotor motorList[NUM_MOTORS];
//We can then store tMotors into this array in the initialization function.
motorList[0] = leftMotor;
...
//When we want to loop through all motors, we loop through with NUM_MOTORS as the limit
for (int i=0; i<NUM_MOTORS; i++) {
tMotor currentMotor = motorList[i];
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment