Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import edu.cmu.ri.createlab.terk.robot.finch.Finch;
- public class SourceOfLight {
- static Finch myFinch = new Finch();
- static int minimumrequirment = 30; //the min requirment for light to be used
- static int leftlight = myFinch.getLeftLightSensor(); //changed the variable to make it easier for me to understand and read the lines of code
- static int rightlight = myFinch.getRightLightSensor(); //changed the variable to make it easier for me to understand and read the lines of code
- public static void main (String args[]) {
- FindingLight();
- LightSensor ();
- FollowLight();
- StopProgram();
- }
- public static void FindingLight(){
- while(leftlight<minimumrequirment && rightlight<minimumrequirment) {
- myFinch.setLED(255,200,0); //change to yellow
- myFinch.setWheelVelocities(100,100,4000); // moving at a slow speed for 4 seconds
- }
- }
- public static void LightSensor(){
- if(leftlight > minimumrequirment && rightlight > minimumrequirment) { //if the sensors are greater than the min requirment then go to BrightnessLevel
- myFinch.buzz(500, 2000); //finch buzzes when sees light
- BrightnessLevel();
- }
- else {
- myFinch.setWheelVelocities(0,0,500); //if no light for 4 seconds, stop finch for 1/2 a second
- myFinch.setWheelVelocities(0,(int) 0.500); //turn finch left or right 90 degrees
- FindingLight();
- }
- }
- public static void BrightnessLevel(){ //making finch beak change Brightness
- if(leftlight > 0 && leftlight <=85 && rightlight > 0 && rightlight <=85 );{ //if finch sensors are between these variables, then the brightness changes
- myFinch.setLED(85,0,0);
- }
- if(leftlight >= 86 && leftlight <=170 && rightlight >= 86 && rightlight <=170) {
- myFinch.setLED(170,0,0);
- }
- if(leftlight >= 171 && leftlight <255 && rightlight >= 171 && rightlight <=255) {
- myFinch.setLED(255,0,0);
- }
- }
- public static void FollowLight() {
- while(leftlight > minimumrequirment && rightlight > minimumrequirment) { //When light is on, follow it
- myFinch.setWheelVelocities(100, 100);
- }
- }
- public static void StopProgram() {
- while(myFinch.isBeakUp()) { //when Finch tails up
- //ask user for log
- System.out.println("Do you want to display the log?");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement