My finch task following a light source (java)

1.4k views Asked by At

I am supposed to make my finch follow a light source, with the following requirements:

-make the finch move towards the light source - set led colour to blue when light source is detected

  • if no light source, finch doesn't move.
  • sets led colour to red.

But I'm getting a syntax error on the last bit.

myf.quit(); (unreachable code is the error) 

And my code also doesn't do the required tasks it seems. Where would the issues be?

My code:

import edu.cmu.ri.createlab.terk.robot.finch.Finch;
public class Myfinchtask {

public static void main(String[] args) {

    Finch myf = new Finch();
    int[] lightsensors =  myf.getLightSensors();
    int meetsthreshold = 300;
    int lightsensorsaverage = 0;

    while(true){

        lightsensors =  myf.getLightSensors();
        lightsensorsaverage = (lightsensors[0]+lightsensors[1])/2;

        if (lightsensorsaverage < meetsthreshold)
        {
            myf.stopWheels();
            myf.setLED(100, 0, 0);

            while (lightsensorsaverage < meetsthreshold){

                lightsensors =  myf.getLightSensors();
                lightsensorsaverage = (lightsensors[0]+lightsensors[1])/2;

                if (lightsensorsaverage > meetsthreshold){

                    myf.setLED(0, 0, 100);
                    myf.setWheelVelocities(100, 100);


                }
            }


            }
        }

    myf.quit();
    System.exit(0);

    }


}
0

There are 0 answers