Page 31
Code
Note: For improved readability as the program executes, the Link specific function
display_printf
is
used in place of
printf
, since
printf
will scroll the screen once it has reached the last row of the display.
display_printf(
<
col
>
,
<
row
>
,
<
string
>
, . . .)
Performs a standard
printf
starting at screen location
col
,
row,
limited to
columns 0 through 41
and rows 0 through 9 (fewer rows if extra buttons are turned on). The effect is a print in place
to the screen. Use of '\n' in the string will distort the outcome. Excess text for any row is
truncated.
/* For a servo plugged into port 0 and initially centered on the
camera's field of vision, this program rotates the servo to keep it
pointing towards the largest object for color channel 0 as the object is
moved about */
int
main() {
int
offset, x, y;
enable_servo(
0
);
// enable servo
camera_open(LOW_RES);
// activate camera
camera_update();
// get most recent camera image and process it
while
(side_button() ==
0
) {
x = get_object_center(
0
,
0
).x;
// get image center x data
y = get_object_center(
0
,
0
).y;
// and y data
if
(get_object_count(
0
) >
0
) {
// there is a blob
display_printf(
0
,
1
,
"Center of largest blod: (%d,%d) "
,x,y);
offset=
5
*(x-
80
);
// amount to deviate servo from center
set_servo_position(
0
,
1024
+offset);
}
else
display_printf(
0
,
1
,
"No object in sight "
);
msleep(
200
);
// don't rush print statement update
camera_update();
// get new image data before repeating
}
disable_servos();
camera_close();
printf(
"All done\n"
);
}
Содержание KIPR Link
Страница 1: ...KIPR Link Manual Version BB2014 1 1...