Question

I have been working on a program to make a robot follow a sound, but I keep getting weird compiler errors. I'm guessing that I made some mistake that threw the compiler off the rails.

#define TICKS_TO_SAMPLE 6
#define MS_TO_SAMPLE 100
#define TIME_TO_QUIET 250
#define ONE_THIRD 480
#define SAMPLE_DEPTH 20
#define NUM_OF_MOVEMENTS 6
#define TIME_MOVING 1000
#define MIC SENSOR_1

int gauge()
{
int soundMax = 0;
for(int tick = 0; tick < TICKS_TO_SAMPLE; tick++){
    if(MIC > soundMax){
        soundMax = MIC;
    }
    Wait(MS_TO_SAMPLE);
}
return soundMax;
}

int soundFind(int width)
{
int firstMax = 0;
firstMax = gauge();
OnFwd(OUT_A, 75);
Wait(width);
Off(OUT_AC);
Wait(TIME_TO_QUIET);
int secondMax = 0;
secondMax = gauge();
OnRev(OUT_A, 75);
Wait(width*2);
Off(OUT_AC, 75);
Wait(TIME_TO_QUIET);
int thirdMax = 0;
thirdMax = gauge();
if(firstMax >= secondMax && firstMax >= thirdMax)
{
    OnRev(OUT_A, 75);
    Wait(width);
    Off(OUT_AC);
    Wait(TIME_TO_QUIET);
}
else
    {
    if(secondMax >= firstMax && secondMax >= thirdMax)
    {
        OnRev(OUT_A, 75);
        Wait(width*2);
        Off(OUT_AC);
        Wait(TIME_TO_QUIET);
    }
}
if(width > SAMPLE_DEPTH)
{
    return width/3;
}
else{
    return 0;
}
}
task main()
 {
 int startingAngle = ONE_THIRD;
 SetSensorSound(IN_1);
 for(int movements = 0; movements < NUM_OF_MOVEMENTS; movements++){
    startingAngle = soundFind(ONE_THIRD);
    while(startingAngle > SAMPLE_DEPTH)
    {
     startingAngle = soundFind(ONE_THIRD);
    }
    OnRev(OUT_AC, 75);
    Wait(TIME_MOVING);
    Off(OUT_AC);
}
}

spits out

line 32 Error: ')' expected
line 32 Error: ';' expected

and

Error: Unmatched close parenthesis

in lines 32, 33, 35-39, 40, 45-48, 51, 58, 60-64, 66-68

Was it helpful?

Solution

The Off() function only takes one parameter, the motor ports. You're trying to pass a power value as a second parameter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top