position = _positions[i];
-
break;
-
}
-
}
30
return
position;
-
}
-
};
-
The code defines several member variables:
ten team member names,
on the team, and we store the position (angle) of the team member s name
on the Blaminatr display in
The constructor expects an array of strings that contains the team members
names and that is terminated by a NULL pointer. We store a reference to the
list, and then we calculate the number of team members. We iterate over the
array until we find a NULL pointer. All this happens in lines 10 to 13.
Then we calculate the position of each team member s name on the Blaminatr s
display. Every team member gets his or her fair share on the 180-degree
display, and the Blaminatr will point to the share s center, so we divide the
share by 2. We store the positions in the
the
_members
array. That means the first entry of
of the first team member, and so on.
With the
get_position
name. We walk through the
the right member using the
return the corresponding entry of the
member with the name we are looking for, we return 0.
Implementing a
Blaminatr
Motors/Blaminatr/Blaminatr.ino
#include <Servo.h>
const unsigned int
const unsigned int
class
Blaminatr {
Team
_team;
Servo _servo;
public:
Blaminatr(const
Team& team) : _team(team) {}
void attach(const int
_servo.attach(sensor_pin);
Chapter 13. Controlling Motors with Arduino
contains the actual number of people
_num_members
_positions
.
method, we get back the position belonging to a certain
_members
array and check whether we have found
function. As soon as we ve found it, we
strcmp
_positions
class is easy now:
MOTOR_PIN = 9;
MOTOR_DELAY = 15;
sensor_pin) {
www.it-ebooks.info
_members
contains a list of up to
array that corresponds to
_positions
_positions
contains the position
array. If we can t find a team
232
report erratum
discuss
Need help?
Do you have a question about the Arduino Uno and is the answer not in the manual?