/*
 * registering functions to load algorithms at runtime
 */
int i2c_pca_add_bus(struct i2c_adapter *adap)
{
	int rval;

	rval = pca_init(adap);
	if (rval)
		return rval;

	return i2c_add_adapter(adap);
}
Exemple #2
0
/* 
 * registering functions to load algorithms at runtime 
 */
int i2c_pca_add_bus(struct i2c_adapter *adap)
{
	struct i2c_algo_pca_data *pca_adap = adap->algo_data;
	int rval;

	/* register new adapter to i2c module... */
	adap->algo = &pca_algo;

	adap->timeout = 100;		/* default values, should	*/
	adap->retries = 3;		/* be replaced by defines	*/

	if ((rval = pca_init(pca_adap)))
		return rval;

	rval = i2c_add_adapter(adap);

	return rval;
}
/*
* Function Name: main
* Input: None
* Output: int to inform the caller that the program exited correctly or
* incorrectly (C code standard)
* Logic: constantly monitors the sensor value and blows buzzer above a defined threshold value. 
* Example Call: Called automatically by the Operating System
*
*/
void main()
{
	unsigned int sensor2_value=0; //variable to store proximity sensor2 value
 	unsigned int sensor3_value=0; //variable to store proximity sensor3 value
 	unsigned int sensor4_value=0; //variable to store proximity sensor4 value
 	unsigned char i=0;
 	output_enable = 0;
 	start_conv = 0;    //de-assert all control signals to ADC
 
 	buzzer = 1; 	//buzzer off
 	lcd_init(); 	//Initialize LCD
 	pca_init();		//initialize PCA for velocity control
 	lcd_clear();  	//clears LCD
 	forward();
 	left_motor_velocity(0x2F);			
	right_motor_velocity(0x2F);
 while(1)
 {
	sensor2_value=ADC_conversion(3);
	sensor3_value=ADC_conversion(0);
	sensor4_value=ADC_conversion(7);
	
	lcd_print(1,1,sensor2_value,3);
	lcd_print(1,5,sensor3_value,3);
	lcd_print(1,9,sensor4_value,3);
	
	if(sensor2_value<50 || sensor3_value<50 || sensor4_value<50) //obstacle detected
	{
	stop();
	delay_ms(1000);
	buzzer=0;	//buzzer on
	delay_ms(2000);	 
	buzzer=1;	//buzzer off	
	break; 
	}			
 }
} //main ends here
void main()
{
 unsigned char i=0;
 output_enable = 0;
 start_conv = 0;    //de-assert all control signals to ADC
 
 buzzer = 1;  //buzzer off
 lcd_init(); //Initialize LCD
 pca_init(); //Initialize PCA to genarate PWM

forward();
left_motor_velocity(0x4F);  //0x00 will give full (100% duty cycle) velocity, while 0xFF will give zero (0% duty cycle) velocity. Any value in between 0x00 and 0xFF will give intermediate velocity.			
right_motor_velocity(0x4F); //0x00 will give full (100% duty cycle) velocity, while 0xFF will give zero (0% duty cycle) velocity. Any value in between 0x00 and 0xFF will give intermediate velocity.


 while(1)
 {
  for(i=0;i<8;i++)	 //Doing ADC conversion
  {
  data_array[i] = ADC_conversion(i);
  }

  left_whiteline = data_array[4];   
  center_whiteline = data_array[5];
  right_whiteline = data_array[6];
  front_sharp_sensor = data_array[2];

  flag = 0; //reset the flag to 0
     
   //check if robot's center white line sensor is on the white line
  if(center_whiteline < 25)
  {
   flag = 1;  //set the flag to 0 so that further white line sensor comparision is disabled
   left_motor_velocity(0x4F);  //left and right motor is at same velocity
   right_motor_velocity(0x4F);
  }

  //robot is drifting towards left side, increase velocity of the left wheel and decrease velocity of the right wheel
  if ((left_whiteline > 25) && (flag == 0))
  {
   flag = 1;  //set the flag to 0 so that further white line sensor comparision is disabled
   left_motor_velocity(0x3F);   //increase left motor velocity
   right_motor_velocity(0x5F);	//decrease  right motor velocity
  }

  //robot is drifting towards right side, decrease velocity of the left wheel and increase velocity of the right wheel
  if ((right_whiteline > 25) && (flag == 0))
  {
   flag = 1;  //set the flag to 0 so that further white line sensor comparision is disabled
   left_motor_velocity(0x5F);	//decrease  right motor velocity
   right_motor_velocity(0x3F);  //increase left motor velocity
  }

  if(front_sharp_sensor >= 110) // obstacle is near the robot, stop and turn on the buzzer
  {
   stop();
   buzzer = 0;  //buzzer on
  }
  
  else
  {
   forward();
   buzzer = 1;  //buzzer off
  }

  if((left_whiteline > 25) && (center_whiteline > 25) && (right_whiteline > 25)) // no whiteline is detected, stop (buzzer will not turn on)
  {
   stop();
  }
  
  lcdprint(data_array);//call this function to print the array onto the screen
  delay_ms(250);
 }
}