Beispiel #1
0
        public static void Main(string[] args)
        {
            ManualResetEvent terminateProgram = new ManualResetEvent(false);
            string           fbToken          = "CAACpSl1Qm3cBAHAMyZAY...";//This is not valied
            var          fb          = new FacebookClient(fbToken);
            Font         f           = Font.MediumFont;
            Point        offset      = new Point(0, 25);
            Point        p           = new Point(10, Lcd.Height - 75);
            Point        boxSize     = new Point(100, 24);
            Rectangle    box         = new Rectangle(p, p + boxSize);
            var          colorSensor = new EV3ColorSensor(SensorPort.In1);
            ButtonEvents buts        = new ButtonEvents();

            LcdConsole.WriteLine("Use color on port1");
            LcdConsole.WriteLine("Enter post value");
            LcdConsole.WriteLine("Esc. terminate");
            buts.EscapePressed += () => {
                terminateProgram.Set();
            };

            buts.EnterPressed += () => {
                Color color = colorSensor.ReadColor();
                Lcd.Clear();
                Lcd.WriteTextBox(f, box + offset * 0, "Color: " + color, true);
                Lcd.WriteTextBox(f, box + offset * 1, "Send to Facebook" + color, true);
                Lcd.Update();
                colorSensor.ReadColor();
                var    me      = fb.Get("monobrick.dk") as JsonObject;
                var    uid     = me["id"];
                string url     = string.Format("{0}/{1}", uid, "feed");
                var    argList = new Dictionary <string, object>();
                argList["message"] = "A program running MonoBrick Firmware was aked to read the color sensor. Color read: " + colorSensor.ReadColor().ToString();
                fb.Post(url, argList);
            };
            terminateProgram.WaitOne();
        }
Beispiel #2
0
        private async Task TestEV3Color()
        {
            //brick.Stop();
            //brick.SetTimeout(250);
            EV3ColorSensor nxtlight = new EV3ColorSensor(BrickPortSensor.PORT_S4, ColorSensorMode.Reflection);
            EV3TouchSensor touch    = new EV3TouchSensor(BrickPortSensor.PORT_S1);
            //brick.Stop();
            //brick.SetupSensors();
            RGBColor rgb;
            await Task.Delay(5000);

            for (int i = 0; i < nxtlight.NumberOfModes(); i++)
            {
                int count = 0;
                while ((count < 100) && !touch.IsPressed())
                {
                    //Debug.WriteLine(string.Format("NXT Touch, Raw: {0}, ReadASString: {1}, IsPressed: {2}, NumberNodes: {3}, SensorName: {4}", touch.ReadRaw(), touch.ReadAsString(), touch.IsPressed(), touch.NumberOfModes(), touch.GetSensorName()));
                    //Debug.WriteLine(string.Format("EV3 Touch, Raw: {0}, ReadASString: {1}, IsPressed: {2}, NumberNodes: {3}, SensorName: {4}", ev3Touch.ReadRaw(), ev3Touch.ReadAsString(), ev3Touch.IsPressed(), ev3Touch.NumberOfModes(), ev3Touch.GetSensorName()));
                    //Debug.WriteLine(string.Format("NXT Sound, Raw: {0}, ReadASString: {1}, NumberNodes: {2}, SensorName: {3}", sound.ReadRaw(), sound.ReadAsString(), sound.NumberOfModes(), sound.GetSensorName()));

                    //brick.UpdateValues();
                    Debug.WriteLine(string.Format("EV3 Color Sensor, Raw: {0}, ReadASString: {1}",
                                                  nxtlight.ReadRaw(), nxtlight.ReadAsString()));
                    rgb = nxtlight.ReadRGBColor();
                    Debug.WriteLine(string.Format("Color: {0}, Red: {1}, Green: {2}, Blue: {3}",
                                                  nxtlight.ReadColor(), rgb.Red, rgb.Green, rgb.Blue));
                    //brick.Stop();
                    //brick.Start();
                    //nxtlight.ColorMode = ColorSensorMode.Ambient;
                    await Task.Delay(1000);

                    //if ((touch.IsPressed()) && ev3Touch.IsPressed())
                    count++;
                    //nxtlight.ColorMode = ColorSensorMode.Color;
                }
                if (nxtlight.ColorMode == ColorSensorMode.Reflection)
                {
                    nxtlight.ColorMode = ColorSensorMode.Color;
                }
                else
                {
                    nxtlight.ColorMode = ColorSensorMode.Reflection;
                }
                //brick.SetupSensors();
                await Task.Delay(5000);
            }
        }
Beispiel #3
0
        public static void Main(string[] args)
        {
            const string to       = "*****@*****.**";
            const string from     = "*****@*****.**";
            const string password = "******";

            ManualResetEvent terminateProgram = new ManualResetEvent(false);
            var          colorSensor          = new EV3ColorSensor(SensorPort.In1);
            ButtonEvents buts        = new ButtonEvents();
            SmtpClient   smptpClient = new SmtpClient("smtp.gmail.com", 587);

            smptpClient.EnableSsl             = true;
            smptpClient.UseDefaultCredentials = false;
            smptpClient.Credentials           = new NetworkCredential(from, password);
            smptpClient.DeliveryMethod        = SmtpDeliveryMethod.Network;
            ServicePointManager.ServerCertificateValidationCallback =
                delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
            { return(true); };
            MailMessage message = new MailMessage();

            message.To.Add(to);
            message.From    = new MailAddress(from);
            message.Subject = "Color mail from my EV3";
            LcdConsole.Clear();
            LcdConsole.WriteLine("Use color on port1");
            LcdConsole.WriteLine("Enter send mail");
            LcdConsole.WriteLine("Esc. terminate");
            buts.EscapePressed += () => {
                terminateProgram.Set();
            };
            buts.EnterPressed += () => {
                LcdConsole.WriteLine("Sending email");
                try{
                    message.Body = "EV3 read color: " + colorSensor.ReadColor();
                    smptpClient.Send(message);
                    LcdConsole.WriteLine("Done sending email");
                }
                catch (Exception e)
                {
                    LcdConsole.WriteLine("Failed to send email");
                    Console.WriteLine(e.StackTrace);
                }
            };
            terminateProgram.WaitOne();
            message = null;
        }
Beispiel #4
0
        public async Task  TestColorSensor()
        {
            EV3ColorSensor color = new EV3ColorSensor(_brick, SensorPort.Port2, ColorSensorMode.Blue);

            color.PropertyChanged += HandleColorPropertyChangedEvent;

            while (false)
            {
                try
                {
                    if (color.ColorMode == ColorSensorMode.Color)
                    {
                        Console.WriteLine($"{color.ReadColor()}");
                    }
                    else
                    {
                        Console.WriteLine(color.CalculateRawAverage());

                        /*
                         * var rgb = color.ReadRGBValues();
                         *
                         * Console.WriteLine($"Red: {rgb.Red}");
                         * Console.WriteLine($"Blue: {rgb.Green}");
                         * Console.WriteLine($"Green: {rgb.Blue}");
                         * Console.WriteLine($"Ambient: {rgb.Blue}");
                         *
                         * var rgb2 = color.ReadRGBColor();
                         *
                         * Console.WriteLine($"Red2: {rgb.Red}");
                         * Console.WriteLine($"Blue2: {rgb.Green}");
                         * Console.WriteLine($"Green2: {rgb.Blue}");
                         */
                    }
                }
                catch (System.Exception ex)
                {
                    Console.WriteLine($"{ex.Message}");
                }

                await Task.Delay(1000);
            }
        }
Beispiel #5
0
        static private void TestEV3Color()
        {
            Console.WriteLine("EV3 sensor color test mode");
            EV3ColorSensor nxtlight = new EV3ColorSensor(_brick, SensorPort.Port2, ColorSensorMode.Green);
            EV3TouchSensor touch    = new EV3TouchSensor(_brick, SensorPort.Port1);
            RGBColor       rgb;

            Thread.Sleep(5000);
            for (int i = 0; i < nxtlight.NumberOfModes(); i++)
            {
                int count = 0;
                while ((count < 100) && !touch.IsPressed())
                {
                    Console.WriteLine($"EV3 Color Sensor, Raw: {nxtlight.ReadRaw()}, ReadASString: {nxtlight.ReadAsString()}");
                    rgb = nxtlight.ReadRGBColor();
                    Console.WriteLine($"Color: {nxtlight.ReadColor()}, Red: {rgb.Red}, Green: {rgb.Green}, Blue: {rgb.Blue}");
                    Thread.Sleep(1000);
                    count++;
                }
                nxtlight.SelectNextMode();
                Thread.Sleep(5000);
            }
        }
Beispiel #6
0
        private static void Main()
        {
            BrickConsole.WriteLine("Start!");
            var speaker = new Speaker(10);

            speaker.Beep();

            var tank            = new Tank(MotorPort.OutD, MotorPort.OutA);
            var irSensorWrapper = new IRSensorLockWrapper(new EV3IRSensor(SensorPort.In2));
            var colorSensor     = new EV3ColorSensor(SensorPort.In1, ColorMode.Color);
            var touchSensor     = new EV3TouchSensor(SensorPort.In3);

            var buttons = new ButtonEvents();

            buttons.EscapePressed += () =>
            {
                tank.Stop();
                BrickConsole.WriteLine("End!");
                speaker.Buzz();
                Environment.Exit(0);
            };

            var remote = new RemoteControl(irSensorWrapper, IRChannel.One);

            remote.ButtonsReleased += btn =>
            {
                tank.Stop();
                BrickConsole.WriteLine("TankState: {0}", tank);
            };

            remote.ButtonsPressed += btn =>
            {
                switch (btn)
                {
                case RemoteButton.LeftUp:
                    tank.StartForward(speed);
                    break;

                case RemoteButton.LeftDown:
                    tank.StartBackward(speed);
                    break;

                case RemoteButton.RightUp:
                    tank.StartSpinLeft(speed);
                    break;

                case RemoteButton.RightDown:
                    tank.StartSpinRight(speed);
                    break;

                case RemoteButton.LeftUp | RemoteButton.LeftDown:
                    BrickConsole.WriteLine("Color: {0}", colorSensor.ReadColor());
                    break;

                case RemoteButton.RightUp | RemoteButton.RightDown:
                    BrickConsole.WriteLine("TouchSensor.IsPressed: {0}", touchSensor.IsPressed());
                    break;

                case RemoteButton.LeftUp | RemoteButton.RightUp:
                    BrickConsole.WriteLine("Distance: {0} cm", irSensorWrapper.Do(x => x.ReadDistance()));
                    break;

                case RemoteButton.Beacon:
                    BrickConsole.WriteLine("Color: {0}", colorSensor.ReadColor());
                    BrickConsole.WriteLine("Distance: {0} cm", irSensorWrapper.Do(x => x.ReadDistance()));
                    BrickConsole.WriteLine("TouchSensor.IsPressed: {0}", touchSensor.IsPressed());
                    break;
                }
            };

            Thread.Sleep(Timeout.Infinite);
        }