static double SetupPapparazziLightThreshold() { // // Get starting light level and establish paparazzi light threshold // double paparazziLightThreshold; double startLight; startLight = gloria.getLeftLightSensor(); paparazziLightThreshold = startLight + 20; return(paparazziLightThreshold); }
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); }
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); }
static double DisplayGetLightLevel(Finch donnie) { double currentLightLevel; currentLightLevel = (donnie.getLeftLightSensor() + donnie.getRightLightSensor()) / 2; return(currentLightLevel); }
/*static bool MonitorCurrentLightLevels(Finch finchRobot, double threshold, int maxSeconds) * { * bool thresholdExceeded = false; * int currentLightLevel; * double seconds = 0; * * * while (!thresholdExceeded && seconds <= maxSeconds) * { * finchRobot.setLED(0, 255, 0); * * currentLightLevel = finchRobot.getLeftLightSensor(); * * DisplayScreenHeader($"Monitor Light Levels"); * Console.WriteLine($"Maximum Light Level: {threshold}"); * Console.WriteLine($"Current Light Level: {currentLightLevel}"); * * if (currentLightLevel > threshold) * { * thresholdExceeded = true; * } * * finchRobot.wait(500); * seconds += 0.5; * } * * finchRobot.setLED(0, 0, 0); * return thresholdExceeded; * }*/ /*static bool MonitorCurrentTemperatureLevels(Finch finchRobot, double threshold, int maxSeconds, string alarmType) * { * bool thresholdExceeded = false; * int currentLevel; * double seconds = 0; * * while (!thresholdExceeded && seconds <= maxSeconds) * { * finchRobot.setLED(0, 255, 0); * * currentLevel = (int)finchRobot.getTemperature(); * * DisplayScreenHeader($"Monitor {alarmType} Levels"); * Console.WriteLine($"Maximum {alarmType} Level: {threshold}"); * Console.WriteLine($"Current {alarmType} Level: {currentLevel}"); * * if (currentLevel > threshold) * { * thresholdExceeded = true; * } * * finchRobot.wait(500); * seconds += 0.5; * } * * return thresholdExceeded; * }*/ static bool MonitorCurrentLevels(Finch finchRobot, double threshold, int maxSeconds, string alarmType) { bool thresholdExceeded = false; int currentLevel = 0; double seconds = 0; while (!thresholdExceeded && seconds <= maxSeconds) { if (alarmType == "temperature") { currentLevel = (int)finchRobot.getTemperature(); } else if (alarmType == "light") { currentLevel = (int)finchRobot.getLeftLightSensor(); } finchRobot.setLED(0, 255, 0); DisplayScreenHeader($"Monitor {alarmType} Levels"); Console.WriteLine($"Maximum {alarmType} Level: {threshold}"); Console.WriteLine($"Current {alarmType} Level: {currentLevel}"); if (currentLevel > threshold) { thresholdExceeded = true; } finchRobot.wait(500); seconds += 0.5; } return(thresholdExceeded); }
/// <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); }
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); } }
static double DisplayGetThreshold(Finch finchRobot, string alarmType) { double threshold = 0; DisplayScreenHeader("Threshold Value"); switch (alarmType) { case "light": Console.WriteLine($"Current Light Level: {finchRobot.getLeftLightSensor()}"); Console.Write("Enter Maximum Light Level:"); threshold = double.Parse(Console.ReadLine()); break; case "temperature": break; default: throw new FormatException(); break; } DisplayContinuePrompt(); return(threshold); }
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); }
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); }
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); }
static void DisplayGetLightData(int numberofDataPoints, double DataPointFrequency, double[] Lightlevels, Finch finchRobot) { DisplayScreenHeader("Get Data"); //++++++++++++++++++++++++++++++++++// // Provide The User Info and Prompt // //++++++++++++++++++++++++++++++++++// //+++++++++++++// // Record Data // //+++++++++++++// for (int index = 0; index < numberofDataPoints; index++) { Lightlevels[index] = finchRobot.getLeftLightSensor(); int milliSeconds = ((int)(DataPointFrequency * 1000)); finchRobot.wait(milliSeconds); //+++++++++++// // Echo Data // //+++++++++++// Console.WriteLine($"Light Level {index + 1}: {Lightlevels[index]}"); } }
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); }
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); }
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); }
//---------------// //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 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); } }
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); }
/// <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 double DisplayGetThreshold(Finch finchRobot, string alarmType) { double threshold = 0; DisplayScreenHeader("Threshold Value"); switch (alarmType) { case "light": Console.WriteLine($"Current Light Level: {finchRobot.getLeftLightSensor()}"); Console.Write("Enter Maximum Light Level [0 - 255]:"); threshold = double.Parse(Console.ReadLine()); break; case "temperature": Console.WriteLine($"Current Temperature: {finchRobot.getTemperature() * (9 / 5) + 32}\u00B0F"); Console.Write("Enter Maximum Temperature:"); threshold = double.Parse(Console.ReadLine()); break; default: Console.WriteLine("Invalid input, you goober."); break; } DisplayContinuePrompt(); return(threshold); }
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); }
static bool MonitorLightLevels(Finch finchRobot, double threshold, int maxSeconds) { bool thresholdExceeded = false; double seconds = 0; int currentLightLevel; while (!thresholdExceeded && seconds <= maxSeconds) { currentLightLevel = finchRobot.getLeftLightSensor(); DisplayScreenHeader("Monitor Light Levels"); Console.WriteLine($"Maximum Light Level: {(int)threshold}"); Console.WriteLine($"Current Light Level: {currentLightLevel}"); if (currentLightLevel >= threshold) { thresholdExceeded = true; } finchRobot.wait(500); seconds += 0.5; } return(thresholdExceeded); }
static double DisplayGetThreshold(Finch finchRobot, string alarmType) { double minthreshold = 0; double maxthreshold = 0; bool ValidInput = false; do { DisplayScreenHeader("Threshold Value"); switch (alarmType) { case "LIGHT": Console.WriteLine($"Current Light Level: {finchRobot.getLeftLightSensor()}"); Console.Write("Enter Maximum Light Level [0 - 255]:"); ValidInput = double.TryParse(Console.ReadLine(), out maxthreshold); if (!ValidInput) { Console.WriteLine("Invalid input, you goober."); DisplayContinuePrompt(); } //Console.WriteLine($"Current Light Level: {finchRobot.getLeftLightSensor()}"); //Console.Write("Enter Minimum Light Level [0 - 255]:"); //ValidInput = double.TryParse(Console.ReadLine(), out minthreshold); //if (!ValidInput) //{ // Console.WriteLine("Invalid input, you goober."); // DisplayContinuePrompt(); //} break; case "TEMPERATURE": Console.WriteLine($"Current Temperature: {finchRobot.getTemperature() * (9 / 5) + 32}\u00B0F"); Console.Write("Enter Maximum Temperature:"); ValidInput = double.TryParse(Console.ReadLine(), out maxthreshold); if (!ValidInput) { Console.WriteLine("Invalid input, you goober."); DisplayContinuePrompt(); } //Console.WriteLine($"Current Temperature: {finchRobot.getTemperature() * (9 / 5) + 32}\u00B0F"); //Console.Write("Enter Minimum Temperature:"); //ValidInput = double.TryParse(Console.ReadLine(), out minthreshold); //if (!ValidInput) //{ // Console.WriteLine("Invalid input, you goober."); // DisplayContinuePrompt(); //} break; default: break; } } while (!ValidInput); DisplayContinuePrompt(); return(maxthreshold); }
static double GetAverageLight() { double leftLightSensor = Sam.getLeftLightSensor(); double rightLightSensor = Sam.getRightLightSensor(); double averageLight = (leftLightSensor + rightLightSensor) / 2; return(averageLight); }
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()}"); }
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()); }
/// <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); }
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); }
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); }
//------------------------// //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); }