View Single Post
  #4   Spotlight this post!  
Unread 25-03-2006, 11:06
jeffmorris jeffmorris is offline
Registered User
no team
 
Join Date: Sep 2005
Location: staten island, ny
Posts: 62
jeffmorris is on a distinguished road
Re: Radio Control and Ultrasonic Sensor

I got Radio Control and Ultrasonic Sensor working properly. Here's the code:

Code:
#include "Main.h"

void main ( void )
{
      int ultrasonic; 
      int joystick02; 

      //Connect Input Wire to Digital Output 11
      //Connect Output wire to Interrupt 1
      //Near = 2, Far = 100
      StartUltrasonic ( 1 , 11 ) ; // interrupt 1= output label on sensor, DO11=input label on sensor
      while ( 1 == 1 )
      {
            ultrasonic = GetUltrasonic ( 1 , 11 ) ;
            joystick02 = GetRxInput ( 1 , 2 ) ;
            if ( ultrasonic > 20 )
            {
                  MotorRcControl ( 0 , 2 , 1 , 0 ) ;
                  MotorRcControl ( 0 , 2 , 2 , 1 ) ;
                  ServoRcControl ( 0 , 4 , 3 , 0 ) ;
            }
            else
            {
                  SetMotor ( 1 , 127 ) ;
                  SetMotor ( 2 , 127 ) ;
                  ServoRcControl ( 0 , 4 , 3 , 0 ) ;
                  if ( joystick02 > 127 )
                  {
                        MotorRcControl ( 0 , 2 , 1 , 0 ) ;
                        MotorRcControl ( 0 , 2 , 2 , 1 ) ;
                  }
                  else
                  {
                        SetMotor ( 1 , 127 ) ;
                        SetMotor ( 2 , 127 ) ;
                  }
            }
      }
}
Is it possible to get another Ultrasonic Sensor for the rear end of the car? I think that in another thread on this forum, someone couldn't get two Ultrasonic Sensors working together without special programming.
Reply With Quote