//-------------------------------------------------------------------------------------
//LCD_Print function
//-------------------------------------------------------------------------------------
void LCD_Print(void) {
	if (new_print){ // Call display function every 400 ms 
		new_print =0;
		lcd_clear();
		lcd_print("\rHeading: %u", heading/10);
		lcd_print("\rRange:%u", range);
		if(Counts==1){	//only call the battery voltage once every second
			battery=(read_AD_input(5));	//switch channels
			battery*=95;
			keypad = read_AD_input(4);	//Allow it stabilize. using this variable as just a throw away
			Counts=0;
		}//end if counts
		lcd_print("\rVoltage:%d", (1*battery));	//prints battery voltage to nearest volt
		lcd_print("\rtrip: %d", near_obstical);
	}//end if new print
}//end LCD print
void Drive_Motor(void){



	MOTOR_PW_AND_STEER_PW = 2028+read_AD_input(4)*5.8;//Normal speed
	//if 65 the first time
		///turn south
		// if 25 the first time
		//stop and start again
	//if 25 the second time
		//stop and do not go again
	if(range<65){
		desired_heading=1800;
	}


	if(range<25){
		MOTOR_PW_AND_STEER_PW=MOTOR_NEUT;
	}

	if(MOTOR_PW_AND_STEER_PW<MOTOR_NEUT){
		MOTOR_PW_AND_STEER_PW=MOTOR_NEUT+10;		//NEED TO GET IT SO IT ALWAYS RUNS FORWARDS
	} //end min val
	if (MOTOR_PW_AND_STEER_PW>3502){
		MOTOR_PW_AND_STEER_PW=3502;
	}//end max val
	PCA0CPL2 = 0xFFFF - MOTOR_PW_AND_STEER_PW;
    PCA0CPH2 = (0xFFFF - MOTOR_PW_AND_STEER_PW) >> 8;//set motor values
}//end drive motor
Example #3
0
int findVoltage(void){
	float advolt;
	adinput = read_AD_input(5); //read the voltage on pin 1.7 and convert it to an unsigned char
	advolt = adinput;
	advolt = advolt/.236; //do some math, get a float out between 0-15(V)
	return advolt;
}
//-------------------------------------------------------------------------------------
//LCD_Print function
//-------------------------------------------------------------------------------------
void LCD_Print(void) {
	if (new_print){ // Call display function every 400 ms 
		new_print =0;
		lcd_clear();
	//	pause();
		lcd_print("\rHeading: %u", heading/10);
		lcd_print("\rRange:%u", range);
		if(Counts==1){	//only call the battery voltage once every second
			battery=(read_AD_input(4));	//switch channels
			battery =(battery/256) * 15;	//Reads once it has stabilized do calc
			keypad = read_AD_input(5);	//Allow it stabilize. using this variable as just a throw away
			Counts=0;
		}//end if counts
		lcd_print("\rVoltage:%d", battery*1000);	//prints battery voltage to nearest volt
	}//end if new print
}//end LCD print
Example #5
0
//-------------------------------------------------------------------------------------
//LCD_Print function
//-------------------------------------------------------------------------------------
void LCD_Print(void) {
	if (new_print) // Call display function every 400 ms 
	{
		new_print =0;
		lcd_clear();
		pause();
		lcd_print("\rHeading: %u", heading/10);
		lcd_print("\rRange:%u", range);
		if(Counts=1)	//only call the battery voltage once every second
		{
			battery=(read_AD_input(5));	//switch channels
			battery =((read_AD_input(5)/256.) * 15.);	//Reads once it has stabilized do calc
			result = read_AD_input(6);	//Allow it stabilize 
			Counts=0;
		}
		lcd_print("\rVoltage:%d", battery);	//prints battery voltage to nearest volt
	}
}
//-------------------------------------------------------------------------------------
//LCD_Print function
//-------------------------------------------------------------------------------------
void LCD_Print(void) {
	if (new_print){ // Call display function every 400 ms 
		new_print =0;
		lcd_clear();
		lcd_print("\rHd: %u, dh: %u", heading/10, desired_heading/10);
		lcd_print("\rRange:%u", range);
		if(Counts==1){	//only call the battery voltage once every second
			battery=(read_AD_input(5));	//switch channels
			battery*=95;
			keypad = read_AD_input(4);	//Allow it stabilize. using this variable as just a throw away
			Counts=0;
		}//end if counts
		if(heading>desired_heading){
			lcd_print("\rVoltage:%d, left", (1*battery));	//hn//prints battery voltage to nearest volt
		} else if(heading<=desired_heading){
			lcd_print("\rVoltage:%d, right", (1*battery));	//prints battery voltage to nearest volt
		}
		lcd_print("\rOtp: %d, Htp: %d", near_obstical, trip_heading_change);
	}//end if new print
}//end LCD print
//*******************modified no AD!!!!!!!!!!!!!
void Drive_Motor(void){
	if (range<=10) {
		//The motor is neutral when the object is 10 cm above the car.
		MOTOR_PW_AND_STEER_PW=MOTOR_NEUT;
	}//end if range = very close
	else if(range > 10){
		MOTOR_PW_AND_STEER_PW = 2028+read_AD_input(4)*5.8;//adjust speed based on potentiometer
		//***********************************************CONSIDER NOT USING RESULT?!?!?!?!
	}//end else normal ad
	PCA0CPL2 = 0xFFFF - MOTOR_PW_AND_STEER_PW;
    PCA0CPH2 = (0xFFFF - MOTOR_PW_AND_STEER_PW) >> 8;//set motor values
}//end drive motor
void Drive_Motor_two(void){
	if (range<=25) {
		if(near_obstical<2){
			MOTOR_PW_AND_STEER_PW = 2028+read_AD_input(4)*5.8;//Normal speed
			desired_heading=1800;
			near_obstical++;
		} else{//The motor is neutral the second time the object is 25 cm above the car.
			MOTOR_PW_AND_STEER_PW=MOTOR_NEUT;
		}//end if else near obistacl	
	}//end if range = very close
	else {
		MOTOR_PW_AND_STEER_PW = 2028+read_AD_input(4)*5.8;//adjust speed based on potentiometer
		if(MOTOR_PW_AND_STEER_PW<2028){
			MOTOR_PW_AND_STEER_PW=2028;		//NEED TO GET IT SO IT ALWAYS RUNS FORWARDS
		} //end min val
		if (MOTOR_PW_AND_STEER_PW>3502){
			MOTOR_PW_AND_STEER_PW=3502;
		}//end max val
		//***********************************************CONSIDER NOT USING RESULT?!?!?!?!
	}//end else normal ad
	PCA0CPL2 = 0xFFFF - MOTOR_PW_AND_STEER_PW;
    PCA0CPH2 = (0xFFFF - MOTOR_PW_AND_STEER_PW) >> 8;//set motor values
}//end drive motor
void Drive_Motor(void){



	MOTOR_PW_AND_STEER_PW = 2028+read_AD_input(4)*5.8;//Normal speed
	//if 65 the first time
		///turn south
		// if 25 the first time
		//stop and start again
	//if 25 the second time
		//stop and do not go again


	if (range<25 && trip_heading_change==1){
		if (range>0){
			near_obstical=1;
		}	
	}
	else if (range<65&&range>0){
		if (trip_heading_change==0){
			trip_heading_change=1;
			desired_heading+=900;
		} 
		//desired_heading=1800;
	}


	if(range<25&&range>0){
		MOTOR_PW_AND_STEER_PW=MOTOR_NEUT;
		//near_obstical=1;
	}
	if(near_obstical==1){
		MOTOR_PW_AND_STEER_PW=MOTOR_NEUT;
	}

	if(MOTOR_PW_AND_STEER_PW<MOTOR_NEUT){
		MOTOR_PW_AND_STEER_PW=MOTOR_NEUT+10;		//NEED TO GET IT SO IT ALWAYS RUNS FORWARDS
	} //end min val
	if (MOTOR_PW_AND_STEER_PW>3502){
		MOTOR_PW_AND_STEER_PW=3502;
	}//end max val
	PCA0CPL2 = 0xFFFF - MOTOR_PW_AND_STEER_PW;
    PCA0CPH2 = (0xFFFF - MOTOR_PW_AND_STEER_PW) >> 8;//set motor values
}//end drive motor