Exemplo n.º 1
0
        private static void AdvoidLightAndObsticales(Finch alma)
        {
            alma.connect();
            int light;
            int lightThreshold = 8;



            DisplayHeader("Finch flees before the spotlight");
            Console.WriteLine("Finch will Avoid the spotlight (flashlight) for 10 seconds. The Finch will also Avoid  Obsitacls");

            light = alma.getRightLightSensor();

            for (int i = 0; i < 17; i++)
            {
                alma.setMotors(100, 100);
                alma.setLED(0, 255, 0);
                alma.wait(500);

                //
                //avoid light
                //
                if ((lightThreshold + light) < alma.getRightLightSensor())
                {
                    alma.setMotors(255, 0);
                    alma.setLED(255, 0, 0);
                    alma.wait(500);
                    alma.setMotors(255, 255);
                    alma.setLED(255, 0, 0);
                    alma.wait(1500);
                    alma.setMotors(0, 255);
                    alma.setLED(255, 0, 0);
                    alma.wait(500);
                }
                if (alma.isObstacleLeftSide())
                {
                    alma.setMotors(0, 255);
                    alma.setLED(255, 0, 0);
                    alma.wait(500);
                }

                else if (alma.isObstacleRightSide())
                {
                    alma.setMotors(255, 0);
                    alma.setLED(255, 0, 0);
                }
            }
            alma.disConnect();
            DisplayContinuePrompt();
        }
        static int LightAlarmDisplaySetMinMaxThresholdValue(string rangeType, Finch finchRobot)
        {
            int minMaxThresholdValue;

            // validation
            bool validResponse;

            do
            {
                DisplayScreenHeader("Min/Max Threshold Value");

                Console.WriteLine($"Current Left light sensor: {finchRobot.getLeftLightSensor()}");
                Console.WriteLine($"Current right light sensor value: {finchRobot.getRightLightSensor()}");
                Console.WriteLine();

                Console.Write($"{rangeType} light sensor value: ");
                validResponse = int.TryParse(Console.ReadLine(), out minMaxThresholdValue);

                if (!validResponse)
                {
                    Console.WriteLine();
                    Console.WriteLine("Please enter an interger.");
                    DisplayContinuePrompt();
                }
            } while (!validResponse);

            //echo value back to user

            DisplayContinuePrompt();

            return(minMaxThresholdValue);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Data Recorder > Get the Data Points
        /// </summary>
        /// <param name="numberOfDataPoints"></param>
        /// <param name="frequencyOfDataPointsSeconds"></param>
        /// <param name="myFinch"></param>
        /// <returns></returns>
        static Tuple <double[], double[]> LightDataRecorderDisplayGetFrequencyOfDataSet(int numberOfDataPoints, double frequencyOfDataPointsSeconds, Finch myFinch)
        {
            double[] lightReadingRight = new double[numberOfDataPoints];
            double[] lightReadingLeft  = new double[numberOfDataPoints];
            DisplayHeader("Get Data Set");

            Console.WriteLine($"\tNumber of Data Points: {numberOfDataPoints}");
            Console.WriteLine($"\tFrequency of Data Points: {frequencyOfDataPointsSeconds}");
            Console.WriteLine();

            Console.WriteLine("\tFinch robot is ready to record light measurement data.");
            Console.WriteLine("\tPress any key to begin.");
            Console.ReadKey();

            double lightLeft, lightRight;
            int    waitVariable;

            for (int index = 0; index < numberOfDataPoints; index++)
            {
                lightLeft  = myFinch.getLeftLightSensor();
                lightRight = myFinch.getRightLightSensor();

                Console.WriteLine($"Left light reading at {index + 1}: {lightLeft}");
                Console.WriteLine($"Right light reading at {index + 1}: {lightRight}");
                lightReadingLeft[index]  = lightLeft;
                lightReadingRight[index] = lightRight;
                waitVariable             = (int)(frequencyOfDataPointsSeconds * 1000);
                myFinch.wait(waitVariable);
            }
            Tuple <double[], double[]> lightReadingVarable = new Tuple <double[], double[]>(lightReadingLeft, lightReadingRight);

            return(lightReadingVarable);
        }
Exemplo n.º 4
0
        static double DisplayGetLightLevel(Finch donnie)
        {
            double currentLightLevel;

            currentLightLevel = (donnie.getLeftLightSensor() + donnie.getRightLightSensor()) / 2;
            return(currentLightLevel);
        }
        static int LightAlarmSetMinMaxThresholdValue(string rangeType, Finch finchRobot)
        {
            int minMaxThresholdValue;

            DisplayScreenHeader("Minimum/Maximum Threshold Value");

            Console.WriteLine($"\tLeft Light Sensor Ambient Light: {finchRobot.getLeftLightSensor()}");
            Console.WriteLine($"\tRight Light Sensor Ambient Light: {finchRobot.getRightLightSensor()}");
            Console.WriteLine();

            Console.Write("\tEnter the {0} light sensor threshold value: ", rangeType);
            int.TryParse(Console.ReadLine(), out minMaxThresholdValue);
            while (minMaxThresholdValue == 0)
            {
                Console.Write("\tYour value must be a non zero integer. Please try again: ");
                int.TryParse(Console.ReadLine(), out minMaxThresholdValue);
            }

            Console.WriteLine();
            Console.WriteLine("\tYour {0} light sensor threshold value is: {1}", rangeType, minMaxThresholdValue);


            DisplayMenuPrompt("Light Alarm");

            return(minMaxThresholdValue);
        }
Exemplo n.º 6
0
        private static (int[], int[]) ExecuteSentryMode(int sentrySec, int sentryFrequency, int[] dataAmountSentryTakes, Finch myFinch, int minMax)
        {
            bool finished = false;

            int[] dataAmountSentryTakesRight = new int[dataAmountSentryTakes.Length];
            (int[], int[])sensoryData;

            DisplayHeader("Sentry Mode.");
            Console.WriteLine("sentry mode will begin, press any key to continue.");
            Console.ReadKey();
            do
            {
                int i = 0;
                if (i == sentryFrequency)
                {
                    finished = true;
                }
                else
                {
                    dataAmountSentryTakes[i]      = myFinch.getLeftLightSensor();
                    dataAmountSentryTakesRight[i] = myFinch.getRightLightSensor();
                    myFinch.wait(sentrySec * 1000);
                    i++;
                }
            } while (!finished);
            sensoryData = (dataAmountSentryTakes, dataAmountSentryTakesRight);
            return(sensoryData);
        }
Exemplo n.º 7
0
        static int LightAlarmSetMinMaxThresholdValue(string rangeType, Finch myFinch)
        {
            int    minMaxThresholdValue = 0;
            bool   validResponse;
            string userResponse;

            do
            {
                DisplayScreenHeader("Minimum/Maximum Threshold Value");

                Console.WriteLine($"Left light sensor ambient light level: {myFinch.getLeftLightSensor()}");
                Console.WriteLine($"Right light sensor ambient light level: {myFinch.getRightLightSensor()}");
                Console.WriteLine();
                Console.Write($"Enter the {rangeType} light sensor value:");
                userResponse = Console.ReadLine();

                if (Regex.IsMatch(userResponse, @"^\d+$")) //A method I stole from https://www.techiedelight.com/identify-string-is-numeric-csharp/
                {
                    validResponse = true;
                    int.TryParse(userResponse, out minMaxThresholdValue);
                }
                else
                {
                    validResponse = false;
                    Console.WriteLine("Hmm.. That didn't work. Press any key to try again");
                    Console.ReadKey();
                }
            } while (!validResponse);

            Console.WriteLine($"The {rangeType} value is set to {minMaxThresholdValue}");


            DisplayMenuPrompt("Light Alarm");
            return(minMaxThresholdValue);
        }
Exemplo n.º 8
0
        private static int LightAlarmDisplaySetMinMaxThresholdValue(Finch fn, string rangeType)
        {
            string minMaxThresholdValue;
            int    nMinMaxThresholdValue;

            DisplayHeader("\n\tMinimum/Maximum Threshold Value");

            Console.WriteLine($"\tLeft light sensor ambient value: {fn.getLeftLightSensor()}");
            Console.WriteLine($"\tRight light sensor ambient value: {fn.getRightLightSensor()}");
            Console.WriteLine();
            Console.Write($"\tEnter The {rangeType} light value: ");

            minMaxThresholdValue = Console.ReadLine();

            char firstChar = minMaxThresholdValue[0];
            bool isNumber  = Char.IsDigit(firstChar);

            if (!isNumber)
            {
                DisplayHeader("\n\tPlease input an integer");
                DisplayContinuePrompt();
                return(LightAlarmDisplaySetTimeToMonitor());
            }
            else
            {
                nMinMaxThresholdValue = int.Parse(minMaxThresholdValue);
                return(nMinMaxThresholdValue);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// third choice
        /// </summary>
        /// <param name="secondsOfCrawl"></param>
        /// <param name="SneakyFinch"></param>
        static void StairWell(int secondsOfCrawl, Finch SneakyFinch)
        {
            bool hit;

            for (int seconds = 0; seconds < secondsOfCrawl * 10; seconds++)
            {
                SneakyFinch.setMotors(255, 255);

                Console.Clear();
                Console.WriteLine(SneakyFinch.getRightLightSensor());
                if (SneakyFinch.getLeftLightSensor() > 150)
                {
                    hit = true;
                    SneakyFinch.setMotors(-100, -25);
                    SneakyFinch.setLED(255, 0, 0);
                    SneakyFinch.wait(3000);
                    SneakyFinch.setMotors(100, 25);
                    SneakyFinch.wait(3000);
                }

                else
                {
                    hit = false;
                    SneakyFinch.setMotors(100, 25);
                    SneakyFinch.setMotors(100, 100);
                }
            }
        }
        static int LightAlarmDisplaySetMinimumMaximumThresholdValue(string rangeType, Finch finchRobot)
        {
            int  minMaxThresholdValue;
            bool validResponse;

            do
            {
                DisplayScreenHeader("Min/Max Threshold Value");

                Console.WriteLine($"Left Light Sensor: {finchRobot.getLeftLightSensor()}");
                Console.WriteLine($"Current Right Light Sensor: {finchRobot.getRightLightSensor()}");
                Console.WriteLine();

                Console.WriteLine($"{rangeType} Light Sensor Value: ");
                validResponse = int.TryParse(Console.ReadLine(), out minMaxThresholdValue);

                if (!validResponse)
                {
                    Console.WriteLine();
                    Console.WriteLine("Please enter a number.");
                    DisplayContinuePrompt();
                }
            } while (!validResponse);

            DisplayContinuePrompt();

            return(minMaxThresholdValue);
        }
Exemplo n.º 11
0
        static double DisplaySetup(Finch myfinch, out double lowerLightThreshold)
        {
            double temperatureDifference;
            double lowerTempThreshold;
            double ambientTemp;
            double lightDifference;
            double ambientLight;

            DisplayHeader("Setup Sentry Bot");

            Console.Write("Enter desired change in temperature:");
            double.TryParse(Console.ReadLine(), out temperatureDifference);

            ambientTemp = myfinch.getTemperature();

            lowerTempThreshold = ambientTemp - temperatureDifference;

            Console.Write("Enter desired change in light:");
            double.TryParse(Console.ReadLine(), out lightDifference);

            ambientLight = myfinch.getLeftLightSensor() + myfinch.getRightLightSensor();

            lowerLightThreshold = ambientLight + lightDifference;

            DisplayContinuePrompt();
            return(lowerTempThreshold);
        }
Exemplo n.º 12
0
        private static double[] DataRecorderDisplayGetDataLights(int numberOfDataPoints, double dataPointFrequency, Finch finchRobot)
        {
            double[] LightReadings = new double[numberOfDataPoints];
            DisplayScreenHeader("Get that Data!");

            Console.WriteLine($"Number of data points:{numberOfDataPoints}");

            Console.WriteLine($"The Frequency at which the data is displayed:{dataPointFrequency}");

            Console.WriteLine();
            Console.WriteLine("\tThe Finch Robot is ready to begin Recording your Light Sensor Data!");
            DisplayContinuePrompt();

            for (int index = 0; index < numberOfDataPoints; index++)
            {
                LightReadings[index] = finchRobot.getRightLightSensor();
                Console.WriteLine($"\tReading{index + 1}: {LightReadings[index].ToString("n2")}");
                int waitInSeconds = (int)(dataPointFrequency * 1000);
                finchRobot.wait(waitInSeconds);
            }
            DisplayContinuePrompt();
            DisplayScreenHeader("Get Data");

            Console.WriteLine();
            Console.WriteLine("\tTable of Light Sensor Data");
            Console.WriteLine();
            DataRecorderDisplayTable(LightReadings);

            Console.WriteLine($"The avedrage of the readings is {LightReadings.Average()}");

            DisplayContinuePrompt();

            return(LightReadings);
        }
Exemplo n.º 13
0
        //---------------//
        //Set Thresh Hold//
        //---------------//
        static int DisplaySetThreshHold(string rangeType, Finch myFinch)
        {
            int    setThreshHold;
            string userResponse;
            bool   validResponse;

            do
            {
                DisplayHeader("Min/Max Threshold Value");

                Console.WriteLine($"Current Left light sensor value: {myFinch.getLeftLightSensor()}");
                Console.WriteLine($"Current right light sensor value: {myFinch.getRightLightSensor()}");
                Console.WriteLine();

                Console.WriteLine("Set Threshold:");
                userResponse = Console.ReadLine();

                validResponse = int.TryParse(userResponse, out setThreshHold);

                if (!validResponse)
                {
                    Console.WriteLine("Incorrect format");
                }
            } while (validResponse == false);

            DisplayContinuePrompt();
            DisplayAlarmSystem(myFinch);
            return(setThreshHold);
        }
        static int LightAlarmSetMinMaxThresholValue(string rangeType, Finch finchRobot)
        {
            int minMaxThresholdValue;
            int minMaxTempValue;

            DisplayScreenHeader("Minimum/Maximum Threshold Value");


            Console.WriteLine($"Left light senor ambient value: {finchRobot.getLeftLightSensor()}");
            Console.WriteLine($"RIght light senor ambient value: {finchRobot.getRightLightSensor()}");
            Console.WriteLine();

            // validate value
            Console.WriteLine($"Enter the {rangeType} light sensor value:");
            int.TryParse(Console.ReadLine(), out minMaxThresholdValue);
            Console.WriteLine($"You have entered {minMaxThresholdValue} as your light sensor value");
            Console.WriteLine();

            // room temperature
            Console.WriteLine($"Room temperature: {finchRobot.getTemperature()}");

            // user response
            Console.WriteLine($"Enter the {rangeType} temperature value: ");
            int.TryParse(Console.ReadLine(), out minMaxTempValue);
            Console.WriteLine($"You have entered {minMaxTempValue} as your temperature value");
            Console.WriteLine();


            DisplayMenuPrompt("Light Alarm");

            return(minMaxThresholdValue);
        }
Exemplo n.º 15
0
        static int LightAlarmSetMinMaxThresholdValue(string RangeType, Finch finchRobot)
        {
            int MinMaxThresholdValue;

            do
            {
                Console.Clear();
                DisplayScreenHeader("Min/Max Threshold Value");
                Console.WriteLine($"\tLeft light sensor ambient value: {finchRobot.getLeftLightSensor()}");
                Console.WriteLine($"\tRight light sensor ambient value: {finchRobot.getRightLightSensor()}");
                Console.WriteLine();

                Console.WriteLine($"\tEnter the {RangeType} light sensor value: ");
                int.TryParse(Console.ReadLine(), out MinMaxThresholdValue);

                if (MinMaxThresholdValue < 0)
                {
                    Console.WriteLine();
                    Console.WriteLine("\tPlease enter a positive threshold value, press any key to continue.");
                    Console.ReadKey();
                }
            } while (MinMaxThresholdValue < 0);

            Console.WriteLine();
            Console.WriteLine($"\tMin/Max threshold value: {MinMaxThresholdValue}");

            DisplayMenuPrompt("Light Alarm");

            return(MinMaxThresholdValue);
        }
Exemplo n.º 16
0
        static double DisplayLightSetup(Finch finch)
        {
            double lightDiff, upperLightThreshold, ambientLight;
            bool   valid;

            do
            {
                Console.Clear();
                DisplayHeader("Setup SentryBot");
                valid = true;
                Console.Write("Enter Desired Change in Light: ");
                if (!double.TryParse(Console.ReadLine(), out lightDiff))
                {
                    valid = false;
                    Console.WriteLine("Invalid Input. Press Any Key To Try Again.");
                    Console.ReadKey();
                }
            } while (!valid);

            ambientLight = (finch.getLeftLightSensor() + finch.getRightLightSensor()) / 2;

            upperLightThreshold = ambientLight + lightDiff;

            DisplayContinuePrompt();

            return(upperLightThreshold);
        }
Exemplo n.º 17
0
 static bool SentryVersusThresholdValue(double lowerTempThreshold, Finch finch, double upperLightThreshold)
 {
     if (finch.getTemperature() <= lowerTempThreshold)
     {
         for (int i = 0; i < 5; i++)
         {
             finch.noteOn(600);
             finch.wait(50);
             finch.noteOff();
         }
         Console.WriteLine("Temperature Reached Threshold. Press Any Key To Continue.");
         Console.ReadKey();
         return(true);
     }
     else if ((finch.getLeftLightSensor() + finch.getRightLightSensor()) / 2 >= upperLightThreshold)
     {
         for (int i = 0; i < 5; i++)
         {
             finch.noteOn(600);
             finch.wait(50);
             finch.noteOff();
         }
         Console.WriteLine("Light Reached Threshold. Press Any Key To Continue.");
         Console.ReadKey();
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 18
0
        static int DisplayLightSetup(Finch sentryBot)
        {
            int  ambientLight;
            int  upperLightThreshold = 0;
            bool validResponse;

            do
            {
                validResponse = true;

                Console.WriteLine();
                Console.Write("Enter desired change in Light Level: ");

                if (int.TryParse(Console.ReadLine(), out int lightDifference))
                {
                    ambientLight = sentryBot.getRightLightSensor();

                    upperLightThreshold = ambientLight + lightDifference;

                    DisplayContinue();
                }
                else
                {
                    Console.WriteLine();
                    Console.WriteLine("Please enter a valid light level");
                    validResponse = false;
                }
            } while (!validResponse);

            return(upperLightThreshold);
        }
Exemplo n.º 19
0
        static int LightAlarmSetMinMaxThresholdValue(string rangeType, Finch finchRobot, bool Valid)
        {
            int minMaxThresholdValue;

            DisplayScreenHeader("Minimum/Maximum threshold value");

            Console.WriteLine($"\tLeft light sensor ambient value: {finchRobot.getLeftLightSensor()} ");

            Console.WriteLine($"\tRight light sensor ambient value: {finchRobot.getRightLightSensor()} ");

            Console.WriteLine();

            // validate value

            Console.WriteLine($"Enter the {rangeType} light sensor value:");
            do
            {
                if (int.TryParse(Console.ReadLine(), out minMaxThresholdValue))
                {
                    Valid = true;
                }
                else
                {
                    Console.WriteLine("\tEnter in a valid number");
                }
            } while (Valid != true);
            Valid = false;

            // echo value

            DisplayMenuPrompt("Light Alarm");

            return(minMaxThresholdValue);
        }
Exemplo n.º 20
0
 static void DataRecorderDisplayCurrentLightSensorValue(Finch finchRobot)
 {
     //display all light sensor values
     Console.SetCursorPosition(2, 8);
     Console.WriteLine($"\tLeft light sensor ambient value: {finchRobot.getLeftLightSensor()}");
     Console.WriteLine("");
     Console.WriteLine($"\tRight light sensor ambient value: {finchRobot.getRightLightSensor()}");
 }
Exemplo n.º 21
0
        static double GetAverageLight()
        {
            double leftLightSensor  = Sam.getLeftLightSensor();
            double rightLightSensor = Sam.getRightLightSensor();
            double averageLight     = (leftLightSensor + rightLightSensor) / 2;

            return(averageLight);
        }
Exemplo n.º 22
0
        static string DisplaySensorsToMonitor(Finch finchRobot)
        {
            DisplayScreenHeader("Sensors to Monitor");
            Console.WriteLine($"Left Light Sensor: {finchRobot.getLeftLightSensor()}\n");
            Console.WriteLine($"Right Light Sensor: {finchRobot.getRightLightSensor()}\n");

            Console.WriteLine("Which light sensor(s) should be monitored (left, right, or both)?:\n");
            return(Console.ReadLine().ToLower());
        }
Exemplo n.º 23
0
 static void TemperatureNominalIndicator(Finch finch)
 {
     finch.setLED(0, 255, 0);
     finch.wait(500);
     Console.WriteLine($"Current Temperature: {finch.getTemperature()}");
     Console.WriteLine($"Current Light Level: {(finch.getLeftLightSensor() + finch.getRightLightSensor()) / 2}");
     finch.setLED(0, 0, 0);
     finch.wait(500);
 }
Exemplo n.º 24
0
        /// <summary>
        /// Gets average light values for above:
        /// </summary>
        /// <param name="myFinch"></param>
        /// <returns></returns>
        public static int GetLightAverage(Finch myFinch)
        {
            // Variables:
            int leftSensor   = myFinch.getLeftLightSensor();
            int rightSensor  = myFinch.getRightLightSensor();
            int lightAverage = (rightSensor + leftSensor) / 2;

            return(lightAverage);
        }
Exemplo n.º 25
0
        //------------------------//
        //Get Current Sensor Value//
        //------------------------//
        static int DisplayGetCurrentSensorValue(Finch myFinch, string sensorToMonitor, int currentLightSensorValue)
        {
            switch (sensorToMonitor)
            {
            case "left":
                currentLightSensorValue = myFinch.getLeftLightSensor();
                break;

            case "right":
                currentLightSensorValue = myFinch.getRightLightSensor();
                break;

            case "both":
                currentLightSensorValue = myFinch.getLeftLightSensor() + myFinch.getRightLightSensor() / 2;
                break;
            }

            DisplayAlarmSystem(myFinch);
            return(currentLightSensorValue);
        }
Exemplo n.º 26
0
 static bool LightAboveThresholdValue(int upperLightThreshold, Finch sentryBot)
 {
     if (sentryBot.getRightLightSensor() >= upperLightThreshold)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 27
0
        static int AlarmSystemDisplaySetMinMaxThresholdValue(string rangeType, Finch finchRobot)
        {
            int    minMaxThresholdValue;
            string choice;
            bool   exit = false;

            DisplayScreenHeader("Min/Maximum Threshold Value");

            Console.WriteLine($"\tLeft light sensor ambient value: {finchRobot.getLeftLightSensor()}");
            Console.WriteLine($"\tRight light sensor ambient value: {finchRobot.getRightLightSensor()}");
            Console.WriteLine();

            Console.Write($"\tEnter the {rangeType} light sensor value: ");
            int.TryParse(Console.ReadLine(), out minMaxThresholdValue);
            //ehco user respose
            Console.WriteLine($"\tYour {rangeType} light sensor value is {minMaxThresholdValue}.");
            Console.WriteLine();
            do
            {
                //Question and validate
                Console.WriteLine($"\tIs {minMaxThresholdValue} The correct light sensor value");
                Console.WriteLine("\t--------------------------------");
                Console.WriteLine("\tY) Yes");
                Console.WriteLine("\tN) No");
                Console.WriteLine("\t--------------------------------");
                choice = Console.ReadLine().ToLower();
                Console.Clear();
                switch (choice)
                {
                case "y":
                    Console.WriteLine("\tValue has been confirmed");
                    exit = true;
                    break;

                case "n":
                    Console.WriteLine("\tPlease re-enter value for light sensor");
                    AlarmSystemDisplaySetMinMaxThresholdValue(rangeType, finchRobot);
                    Console.Clear();
                    break;

                default:
                    Console.WriteLine();
                    Console.WriteLine("\tPlease enter a letter for the menu choice.");
                    DisplayContinuePrompt();
                    Console.Clear();
                    break;
                }
            } while (!exit);

            DisplayMenuPrompt("Alarm system");


            return(minMaxThresholdValue);
        }
        static int LightAlarmCurrentSensorValue(Finch finchRobot, string sensorsToMonitor)
        {
            int currentLightSensorValue = 0;

            switch (sensorsToMonitor)
            {
            case "left":
                currentLightSensorValue = finchRobot.getLeftLightSensor();
                break;

            case "right":
                currentLightSensorValue = finchRobot.getRightLightSensor();
                break;

            case "both":
                currentLightSensorValue = (finchRobot.getLeftLightSensor() + finchRobot.getRightLightSensor()) / 2;
                currentLightSensorValue = (int)(finchRobot.getLightSensors().Average());
                break;
            }
            return(currentLightSensorValue);
        }
Exemplo n.º 29
0
        private static void AdvoidLight(Finch Alma)
        {
            alma.connect();
            int light;
            int lightThreshold = 8;



            DisplayHeader("Finch flees before the spotlight");
            Console.WriteLine("Finch will Avoid  the spotlight (flashlight) for 10 seconds.");

            light = alma.getRightLightSensor();

            for (int i = 0; i < 17; i++)
            {
                alma.setMotors(100, 100);
                alma.setLED(0, 255, 0);
                alma.wait(500);

                //
                //avoids light
                //
                if ((lightThreshold + light) < alma.getRightLightSensor())
                {
                    alma.setMotors(255, 0);
                    alma.setLED(255, 0, 0);
                    alma.wait(500);
                    alma.setMotors(255, 255);
                    alma.setLED(255, 0, 0);
                    alma.wait(1500);
                    alma.setMotors(0, 255);
                    alma.setLED(255, 0, 0);
                    alma.wait(500);
                }
            }
            alma.disConnect();
            DisplayContinuePrompt();
        }
        /// <summary>
        /// gets light data from user
        /// </summary>
        static void DisplayGetLightData(int numberOfDataPoints, double dataPointFrequency, double[] lights, Finch ros)
        {
            DisplayScreenHeader("Get Light Value");
            Console.WriteLine();
            Console.WriteLine("The Finch Robot will now record your light values.");

            for (int index = 0; index < numberOfDataPoints; index++)
            {
                lights[index] = (ros.getLeftLightSensor() + ros.getRightLightSensor()) / 2;
                int milliseconds = (int)(dataPointFrequency * 1000);
                ros.wait(milliseconds);
                Console.WriteLine($"Light {index + 1}: {lights[index]}");
            }

            DisplayContinuePrompt();

        }