Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.26 KB | None | 0 0
  1. import java.util.Scanner;
  2. import edu.cmu.ri.createlab.terk.robot.finch.Finch;
  3.  
  4. public class SourceOfLight {
  5.     static Finch myFinch = new Finch();
  6.     static int minimumrequirment = 30; //the min requirment for light to be used
  7.     static int leftlight = myFinch.getLeftLightSensor(); //changed the variable to make it easier for me to understand and read the lines of code
  8.     static int rightlight = myFinch.getRightLightSensor(); //changed the variable to make it easier for me to understand and read the lines of code
  9.    
  10. public static void main (String args[]) {
  11.    
  12.     FindingLight();
  13.     LightSensor ();
  14.     FollowLight();
  15.     StopProgram();
  16.    
  17.    
  18. }
  19.  
  20.     public static void FindingLight(){
  21.         while(leftlight<minimumrequirment && rightlight<minimumrequirment) {
  22.         myFinch.setLED(255,200,0); //change to yellow
  23.         myFinch.setWheelVelocities(100,100,4000); // moving at a slow speed for 4 seconds
  24.         }
  25.     }
  26.     public static void LightSensor(){
  27.         if(leftlight > minimumrequirment && rightlight > minimumrequirment) { //if the sensors are greater than the min requirment then go to BrightnessLevel
  28.             myFinch.buzz(500, 2000); //finch buzzes when sees light
  29.             BrightnessLevel();
  30.         }
  31.         else {
  32.             myFinch.setWheelVelocities(0,0,500); //if no light for 4 seconds, stop finch for 1/2 a second
  33.             myFinch.setWheelVelocities(0,(int) 0.500); //turn finch left or right 90 degrees
  34.             FindingLight();
  35.         }
  36.     }
  37.     public static void BrightnessLevel(){ //making finch beak change Brightness
  38.         if(leftlight > 0 && leftlight <=85 && rightlight > 0 && rightlight <=85 );{ //if finch sensors are between these variables, then the brightness changes
  39.             myFinch.setLED(85,0,0);
  40.         }
  41.         if(leftlight >= 86 && leftlight <=170 && rightlight >= 86 && rightlight <=170) {
  42.             myFinch.setLED(170,0,0);
  43.         }
  44.  
  45.         if(leftlight >= 171 && leftlight <255 && rightlight >= 171 && rightlight <=255) {
  46.             myFinch.setLED(255,0,0);
  47.             }
  48.     }
  49.     public static void FollowLight() {
  50.         while(leftlight > minimumrequirment && rightlight > minimumrequirment) { //When light is on, follow it
  51.             myFinch.setWheelVelocities(100, 100);
  52.         }
  53.     }
  54.         public static void StopProgram() {
  55.             while(myFinch.isBeakUp()) { //when Finch tails up
  56.                 //ask user for log
  57.                 System.out.println("Do you want to display the log?");
  58.                
  59.  
  60.             }
  61.  
  62.         }
  63.  
  64.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement