// The function that contains the loop which checks the wall
void check_wall()
{
	
	while (true){
		//Assuming front sensor is port 0, 1 is left and 2 is right
		sensor1_reading = ReadAnalog(0);
		sensor2_reading = ReadAnalog(1);
		sensor3_reading = ReadAnalog(2);
		
		if (check_front = 1)
		{
			
		}
	}
}
Exemple #2
0
void main( void ) {
    unsigned char i = 0;
    // Pins C6 and C7 are used for UART TX and RX respectively
    InitEcoCar();
    ReadAnalog(0);
    J1939_Initialization( TRUE );

    LATB = 0;
    TRISB = 0;
    TRISC = 0;

    ShowBootupAnimation();

    while (J1939_Flags.WaitingForAddressClaimContention)
        J1939_Poll(5);

    // CANbus is now initialized and we can now loop while we check
    // our message receive buffer for new CANbus messages (where all received messages are put).
    while (1) {
        //Receive Messages
        J1939_Poll(10);
        while (RXQueueCount > 0) {
            J1939_DequeueMessage( &Msg );
            LATCbits.LATC5 = 1;

            if ( J1939_Flags.ReceivedMessagesDropped )
                J1939_Flags.ReceivedMessagesDropped = 0;
        }
    }
}
int main(){
InitHardware();
int adc_reading = ReadAnalog(0);
printf("%d\n",adc_reading);
while(1){
adc_reading = ReadAnalog(0);

if (adc_reading > 50){
SetMotor(1,1,255);
SetMotor(2,1,255);
Sleep(1,500000);
}
else{
SetMotor(1,1,0);
SetMotor(2,1,0);
}
}
return;
}
int check_right()
{
	// Reads the value from the right IR sensor
	int sensor3_reading = ReadAnalog(2);
	
	// If the IR sensor returns below 200, it is deemed to be too close to the wall.
	int max_distance_3 = 200;
	
	if (sensor3_reading < max_distance_3)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
int check_left()
{
	// Reads the value from the left IR sensor
	int sensor2_reading = ReadAnalog(1);
	
	// If the IR sensor returns below 200, it is deemed to be too close to the wall.
	int max_distance_2 = 200;
	
	if (sensor2_reading < max_distance_2)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
Exemple #6
0
void GoPiGo::IBoard::ReloadBoardVersion()
{
   Transaction Lock(this);

   int16_t rawdata = 0;
   for (int i = 0; i < 10; ++i)
   {
      rawdata = ReadAnalog(boardversioninfo_pin);
   }

   if (rawdata > 790)
   {
      BoardVersion = 16;
   }
   else
   {
      BoardVersion = 14;
   }
}