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();
                        }
                    }
                }
示例#2
0
 public MainWindow()
 {
     InitializeComponent();
     et.ConnectToBrick();
 }