Sharp sensors in 3pi

This is the “mouse” 3pi with two SHARP GPY0A21 sensors connected in ADC6 (battery) and ADC7 (trimpot) and the main()
C program that makes dodge obstacles.
ullE (LEFT eye) ullD (RIGHT eye)
motorE (motor1) motorD (motor2)

int main()
{
	set_analog_mode(MODE_10_BIT);
	emitters_off();
	// inicializacio del 3pi
	initialize();	// Musica y pushbutton B
	clear();	// LCD

	// Bucle principal.
	lcd_goto_xy(0,0);
	print ("Esq.Dre.");

	while(1)
	// valor max.= 630 a 5 cm y min = 38 a mes de 80cm
	{
		if (!analog_is_converting())
			{ 		
			ullE = analog_read(6);	// es bateria
			lcd_goto_xy(0,1);
			print_long(ullE);
			ullE = sqrt(ullE);
			motorE = 120-9*ullE/2;	// valors entre 25 i 5
			}

		if (!analog_is_converting()) 
			{
			ullD = analog_read(7); 	// es trimpot
			lcd_goto_xy(4,1);
			print_long(ullD);
			ullD = sqrt(ullD);	
			motorD = 120-9*ullD/2;	
			}

		if (ullD > 23 && ullE > 23)	// tira enrera obstacle enfront colision
			{
			for(counter=20;counter<45;counter++)
				{
				motorD = -counter;
				motorE = -counter;
				set_motors(motorD, motorE);
				red_led(1);
				delay_ms(100);
				red_led(0);
				}
			set_motors(0,0);
			}

		if (ullD < 12 && ullE < 12)	// per anar recte ----
			motorD = motorE;

 		set_motors(motorD,motorE);		// !!! motors cambiats !!!!
		delay_ms(100);
	}

}


Hello, Jaume.

Thanks for posting the picture and your code! That looks like a very interesting modification you’ve made; can you tell me more about how your 3pi behaves? Note that if you have a distance sensor connected to ADC6, you might get better readings if you remove the shorting block that connects ADC6 to the battery voltage.

- Ben

The batteries an the trimpot are disconnected. In the picture, the two jumpers ·-· are placed in reverse ¡¡
The code is very basic, just to prove. Now attempts to improve code for speed and collisions. I like add features to the rest of the pins available, the TX, RX pins, pcb expansion kit…
jaume