EasyManuals Logo

Arduino uno User Manual

Arduino uno
311 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #247 background imageLoading...
Page #247 background image
position = _positions[i];
-
break;
-
}
-
}
30
return position;
-
}
-
};
-
The code defines several member variables:
_members
contains a list of up to
ten team member names,
_num_members
contains the actual number of people
on the team, and we store the position (angle) of the team members name
on the Blaminatr display in
_positions
.
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 members name on the Blaminatrs
display. Every team member gets his or her fair share on the 180-degree
display, and the Blaminatr will point to the shares center, so we divide the
share by 2. We store the positions in the
_positions
array that corresponds to
the
_members
array. That means the first entry of
_positions
contains the position
of the first team member, and so on.
With the
get_position
method, we get back the position belonging to a certain
name. We walk through the
_members
array and check whether we have found
the right member using the
strcmp
function. As soon as weve found it, we
return the corresponding entry of the
_positions
array. If we cant find a team
member with the name we are looking for, we return 0.
Implementing a
Blaminatr
class is easy now:
Motors/Blaminatr/Blaminatr.ino
#include <Servo.h>
const unsigned int MOTOR_PIN = 9;
const unsigned int MOTOR_DELAY = 15;
class Blaminatr {
Team _team;
Servo _servo;
public:
Blaminatr(const Team& team) : _team(team) {}
void attach(const int sensor_pin) {
_servo.attach(sensor_pin);
Chapter 13. Controlling Motors with Arduino 232
report erratum discuss
www.it-ebooks.info

Table of Contents

Other manuals for Arduino uno

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Arduino uno and is the answer not in the manual?

Arduino uno Specifications

General IconGeneral
Form factorArduino
CertificationRoHS, FC, CE
Processor model-
Processor frequency- MHz
Microcontroller modelATmega328
Microcontroller frequency16 MHz
DC input voltage7-12 V
Operating voltage5 V
DC current per I/O pin40 mA
Flash memory0.032 MB
Maximum internal memory- GB
SRAM (Static Random Access Memory)2 KB
EEPROM (Electrically Erasable Programmable Read-Only Memory)1 KB
Wi-FiNo
Number of analog I/O pins6
Number of digital I/O pins14
Weight and Dimensions IconWeight and Dimensions
Board dimensions53.4 x 68.6 mm

Related product manuals