static void Main(string[] args) { Legobot et = new Legobot(); et.ConnectToBrick(); /* Home home = new Home(); * et.ConnectToBrick(); * * float[] HomeArray = new float[2]; * int i = 0; * if (home.GoHome == 1) * { * while (et.DetectColour ) * } * while (i < 2) * { * HomeArray[i] = HomeArray[i] + Co * i++; * }*/ Console.WriteLine(et.DetectDistance()); Console.WriteLine("Where is Home? \n" + "Enter 0 for BlackRed. \n" + "Enter 1 for BlueRed \n" + "Enter 2 for BlueYellow \n" + "Enter 3 for YellowBlack."); int Home = Convert.ToInt32(Console.ReadLine()); while (Home > 3) { Console.WriteLine("Please enter a valid selection to continue."); Home = Convert.ToInt32(Console.ReadLine()); } bool RainbowDetected = false; bool PreviousColour = false; bool CurrentColour = false; while (RainbowDetected == false) { Thread.Sleep(2000); float distance = et.DetectDistance(); Console.WriteLine("Distance Detected: " + distance); while (distance > 6) { et.Forward(); Thread.Sleep(500); distance = et.DetectDistance(); Console.WriteLine("Distance Detected: " + distance); if (distance > 147) { et.Reverse(); } } et.DetectColour(); float ColourDetected = et.DetectColour(); Console.WriteLine("Colour Detected: " + ColourDetected); while (PreviousColour == false & CurrentColour == false) { if (Home == 0) //BlackRedLoop { if (ColourDetected == 5) //Red { Thread.Sleep(2000); et.Reverse(); Thread.Sleep(2000); et.Turn15Right(); } else if (ColourDetected == 0) //Black { Thread.Sleep(2000); et.Reverse(); Thread.Sleep(2000); et.Turn15Left(); } else if (ColourDetected == 3) //Blue { Thread.Sleep(2000); et.Reverse(); Thread.Sleep(2000); et.Turn90Right(); } else //1 = Yellow { Thread.Sleep(2000); et.Reverse(); Thread.Sleep(2000); et.Turn90Left(); } } }
private void RedBlackBTN_Click_1(object sender, RoutedEventArgs e) { Debug.WriteLine(et.DetectDistance()); bool ColourOne = false; bool ColourTwo = false; while (ColourOne != true || ColourTwo != true) { Thread.Sleep(2000); float distance = et.DetectDistance(); Debug.WriteLine("Distance Detected: " + distance); while (distance > 6) { et.Forward(); Thread.Sleep(500); distance = et.DetectDistance(); Debug.WriteLine("Distance Detected: " + distance); } et.DetectColour(); float ColourDetected = et.DetectColour(); Console.WriteLine("Colour Detected: " + ColourDetected); //BlackRedLoop if (ColourDetected == 5) //Red { Thread.Sleep(2000); et.Reverse(); Thread.Sleep(2000); et.Turn15Right(); ColourOne = true; Debug.WriteLine(ColourOne); Debug.WriteLine(ColourTwo); } else if (ColourDetected == 0) //Black { Thread.Sleep(2000); et.Reverse(); Thread.Sleep(2000); et.Turn15Left(); ColourTwo = true; Debug.WriteLine(ColourOne); Debug.WriteLine(ColourTwo); } else if (ColourDetected == 3) //Blue { Thread.Sleep(2000); et.Reverse(); Thread.Sleep(2000); et.Turn90Right(); ColourOne = false; ColourTwo = false; Debug.WriteLine(ColourOne); Debug.WriteLine(ColourTwo); } else //1 = Yellow { Thread.Sleep(2000); et.Reverse(); Thread.Sleep(2000); et.Turn90Left(); ColourOne = false; ColourTwo = false; Debug.WriteLine(ColourOne); Debug.WriteLine(ColourTwo); } } et.BaseFound(); Debug.Write("Home Base Found"); }