Page 172 - PDA Robotics Using Your Personal Digital Assistant to Control Your Robot
P. 172

PDA 07  5/27/03  8:44 AM  Page 148
                          main() {                   PDA Robotics
                             //
                             // The value from the range finder
                             //
                             int range_value;

                             //
                             // The command sent from the PDA
                             //

                             char cmd;
                             //
                             // Set up port A as analog, pin A0 is connected
                             // to the sharp GP2D12 infrared range finder
                             //

                             setup_port_a( ALL_ANALOG );
                             setup_adc( ADC_CLOCK_INTERNAL );
                             set_adc_channel( 0 );

                             //
                             // Set the B port pins that interface to the
                             // L298 motor controller low to ensure no
                             // motor movement on startup. Pins B2 & B3
                             // control Motor 1 and B4 & B5 control Motor 2.
                             //

                             output_low(PIN_B2);
                             output_low(PIN_B3);
                             output_low(PIN_B4);
                             output_low(PIN_B5);
                             output_low(PIN_B6);
                             output_low(PIN_B7);
                             delay_cycles(3);

                             //
                             // Let the PDA know we are alive by sending some data (A space characater)
                             //

                             fprintf(PDA, " ");
                             //
                             // Loop indefinitely handling commands from the PDA
                             //

                             while (1){
                               //

                          148
   167   168   169   170   171   172   173   174   175   176   177