Ok, now that you have it working you may want to consider ways of further simplifying the code as well as interfacing to your motors.
Here is how I would design it. I will explain how it works but don't hesitate to do your own thing.
The code below calculates an index of steps from max left to max right. You set the number of left/right steps you want by defining the value for INDEX_STEPS. The example has three steps on each direction (left, center left and center). Note there is a theoretical value of 'hard left' and 'hard right' that could occur if one mic was above the threshold and the other was zero. This can't happen in the real world but we include it in the code so that test values are handled correctly.
The raw index is calculated by multiplying directionVal by the number of steps and dividing this by the loudest mic value i.e.: (directionVal * INDEX_STEPS) / valRight ;
The index will be negative when the left mic is louder so by adding the number of steps we get the index to range from 0 to the total number of steps (i.e. 6) : directionIndex = INDEX_STEPS + ((directionVal * INDEX_STEPS) / valRight);
This enables us to use the index to access the correct action for the current position: Serial.print( directionText[directionIndex]);
The index could also be used to access constants for your steering control. If you used a servo for steering you could have an array of servo angles where 0 degrees was full left, 90 degrees center and 180 degrees full right, for example: int ServoAngles[] = {0, 0,45,90,135,180,180};
Or if you wanted to use differential wheel speeds to steer you could have an array of PWM steering values for each motor, for example:
Int leftMotor[] = {255,255,127,0,0,0,0} ;
Int rightMotor[] = {0,0,0,0,127,255,255};
anyway, the explanation is longer than the code:
int leftmicPin = 0;
int rightmicPin = 1;
int valLeft = 0;
int valRight = 0;
int directionVal = 0;
int directionIndex = 0;
#define INDEX_STEPS 3 // this is the number of steps we want in our index of directions
// below are the text strings indicating sound direction.
// Note that hard left and hard right should never occur in the real world
// because this index is only returned when the sound from one mic is greater than 500 and the other mic is 0
char* directionText[] = {"hard Left", "left", "center left", "center", "center right", "right", "hard right"};
void setup() {
Serial.begin(9600);
}
void loop()
{
valLeft = analogRead(leftmicPin); //Read all the sound sensor outputs
valRight = analogRead(rightmicPin);
if(valLeft >= 500 || valRight >= 500) {
directionVal = valRight - valLeft; //Determine how far; more negative = more to the left; 0 = at absolute center; more positive = more to the right
if(directionVal >= 0) // left is smaller so get positive index
directionIndex = INDEX_STEPS + ((directionVal * INDEX_STEPS) / valRight); // 3 if center, 4 if center right, 5 if right
else
directionIndex = INDEX_STEPS + ((directionVal * INDEX_STEPS) / valLeft); // 1 if left, 2 if center left, 3 if center
Serial.print( directionText[directionIndex]);
}
}
p.s. if you do want to stay with a version that uses if statements instead of an index, you need to use curley brackets after your first if statment testing if either value >= 500.