/* Lab Demonstration Program for Servo Motor and... void main () {

advertisement
/*
Lab Demonstration Program for Servo Motor and IR Receiver
*/
void main ()
{
int deg, ir_now, max_ir, max_deg, deg_step=1, overshoot=10;
float angle, delay_time=0.04;
/* Set the desired IR frequency and turn on the transmitter.
*/
set_ir_transmit_frequency(125);
ir_transmit_on();
/* Turns the servo on and initializes max to 0 */
while(1)
{
printf("Press the Start Button to Begin\n");
start_press ();
servo_on ();
servo_deg (0.);
sleep (0.2);
/* Set the desired IR receiver frequency and turn on the IR sensor.
*/
max_ir = 0;
max_deg = 0;
set_ir_receive_frequency (125);
ir_receive_on ();
sleep (0.1);
/*
/*
/*
/*
/*
Tells the servo to turn at "deg_step" intervals for 180 degrees
and has it pause for a little time between readings. As it scans,
the current value of the position in degrees and the IR reading,
as well as the the max IR reading value and its position value, is
is displayed on the LCD.
for (deg=0; deg <= 180; deg = deg + deg_step)
{
angle = (float) deg;
servo_deg (angle);
sleep (delay_time);
ir_now = ir_counts(5);
if (max_ir < ir_now)
{
max_ir = ir_now;
max_deg = deg;
}
printf("D=%d,IR=%d, maxD=%d, maxIR=%d\n",
deg, ir_now, max_deg, max_ir);
}
/* Returns the servo to the position of max IR reading.
*/
ir_receive_off ();
max_deg = max_deg - overshoot;
servo_deg ((float)(max_deg));
printf ("Deg=%d, IR=%d Start does over\n", max_deg, max_ir);
start_press ();
}
}
*/
*/
*/
*/
*/
Download