- #1
Lancelot59
- 646
- 1
I'm working on a project for my microcontrollers course. It involves programming a pathfinding robot that uses 5 reflected light sensors to follow a track. Since the code that we were provided that was written I don't know how long ago fails as hard as it does I decided to re-write the whole control system.
Only thing is to simplify things when programming the logic into this thing I want to use enums to control the speed of each motor.
I have NO clue how this guy put the code together, but it's just a big partially commented mess.
Here is the applicable code from the header file
and here is the code from the source file
Now what I want to do is have my array (or vector, I like them better) with similar values, with enumerated values for each setting. I just don't get how this stuff goes together.
How do I go about enumerating values to the values in the array/vector? I know how to assign them when creating the array by making the values equal something, but this fellow seemed to create the values, then enumerate them.
Only thing is to simplify things when programming the logic into this thing I want to use enums to control the speed of each motor.
I have NO clue how this guy put the code together, but it's just a big partially commented mess.
Here is the applicable code from the header file
Code:
enum motor_speed_setting { rev_fast, rev_medium, rev_slow, stop, slow, medium, fast };
enum motor_selection { left, right };
void set_motor_speed(enum motor_selection the_motor, enum motor_speed_setting motor_speed, int speed_modifier);
and here is the code from the source file
Code:
void set_motor_speed(enum motor_selection the_motor, enum motor_speed_setting motor_speed, int speed_modifier)
{
const static int motor_speeds[] = { -800, -600, -400, 0, 400, 600, 800};
int duty_cycle;
enum e_direction {reverse,forward} dir_modifier= forward;
Now what I want to do is have my array (or vector, I like them better) with similar values, with enumerated values for each setting. I just don't get how this stuff goes together.
How do I go about enumerating values to the values in the array/vector? I know how to assign them when creating the array by making the values equal something, but this fellow seemed to create the values, then enumerate them.
Last edited: