Example #1
0
        private async void Setup()
        {
            this.hat = await GIS.FEZHAT.CreateAsync();

            //this.hat.S1.SetLimits(500, 2400, 0, 180);
            //this.hat.S2.SetLimits(500, 2400, 0, 180);

            this.timer          = new DispatcherTimer();
            this.timer.Interval = TimeSpan.FromMilliseconds(100);

            this.timer.Start();

            Mobil            = new MobilRemote();
            this.timer.Tick += (a, b) =>
            {
                /*
                 * double x, y, z;
                 *
                 * this.hat.GetAcceleration(out x, out y, out z);
                 *
                 * this.LightTextBox.Text = this.hat.GetLightLevel().ToString("P2");
                 * this.TempTextBox.Text = this.hat.GetTemperature().ToString("N2");
                 * this.AccelTextBox.Text = $"({x:N2}, {y:N2}, {z:N2})";
                 * this.Button18TextBox.Text = this.hat.IsDIO18Pressed().ToString();
                 * this.Button22TextBox.Text = this.hat.IsDIO22Pressed().ToString();
                 * this.AnalogTextBox.Text = this.hat.ReadAnalog(GIS.FEZHAT.AnalogPin.Ain1).ToString("N2");
                 */
                if (isNavigating)
                {
                    return;
                }
                isNavigating      = true;
                this.hat.D2.Color = GIS.FEZHAT.Color.Black;
                this.hat.D3.Color = GIS.FEZHAT.Color.Black;

                switch (Mobil.Arah)
                {
                case MobilRemote.ArahJalan.Maju:
                    this.hat.MotorA.Speed = 1.0;
                    this.hat.MotorB.Speed = 1.0;
                    this.hat.D2.Color     = GIS.FEZHAT.Color.Green;
                    this.hat.D3.Color     = GIS.FEZHAT.Color.Green;
                    break;

                case MobilRemote.ArahJalan.Mundur:
                    this.hat.MotorA.Speed = -1.0;
                    this.hat.MotorB.Speed = -1.0;
                    this.hat.D2.Color     = GIS.FEZHAT.Color.Yellow;
                    this.hat.D3.Color     = GIS.FEZHAT.Color.Yellow;
                    break;

                case MobilRemote.ArahJalan.Kiri:
                    this.hat.MotorA.Speed = -0.7;
                    this.hat.MotorB.Speed = 0.7;
                    this.hat.D2.Color     = GIS.FEZHAT.Color.Blue;
                    this.hat.D3.Color     = GIS.FEZHAT.Color.Blue;
                    break;

                case MobilRemote.ArahJalan.Kanan:
                    this.hat.MotorB.Speed = -0.7;
                    this.hat.MotorA.Speed = 0.7;
                    this.hat.D2.Color     = GIS.FEZHAT.Color.Cyan;
                    this.hat.D3.Color     = GIS.FEZHAT.Color.Cyan;
                    break;

                case MobilRemote.ArahJalan.Stop:
                    this.hat.MotorA.Speed = 0.0;
                    this.hat.MotorB.Speed = 0.0;
                    this.hat.D2.Color     = GIS.FEZHAT.Color.Red;
                    this.hat.D3.Color     = GIS.FEZHAT.Color.Red;
                    break;
                }
                isNavigating = false;
            };
            timer.Start();

            client = new MqttClient(MQTT_BROKER_ADDRESS);
            string clientId = Guid.NewGuid().ToString();

            client.Connect(clientId);
            SubscribeMessage();
        }
Example #2
0
        private async void Setup()
        {
            this.hat = await GIS.FEZHAT.CreateAsync();
            //this.hat.S1.SetLimits(500, 2400, 0, 180);
            //this.hat.S2.SetLimits(500, 2400, 0, 180);

            this.timer = new DispatcherTimer();
            this.timer.Interval = TimeSpan.FromMilliseconds(100);
        
            this.timer.Start();

            Mobil = new MobilRemote();
            this.timer.Tick += (a,b) =>
            {
                /*
                double x, y, z;

                this.hat.GetAcceleration(out x, out y, out z);

                this.LightTextBox.Text = this.hat.GetLightLevel().ToString("P2");
                this.TempTextBox.Text = this.hat.GetTemperature().ToString("N2");
                this.AccelTextBox.Text = $"({x:N2}, {y:N2}, {z:N2})";
                this.Button18TextBox.Text = this.hat.IsDIO18Pressed().ToString();
                this.Button22TextBox.Text = this.hat.IsDIO22Pressed().ToString();
                this.AnalogTextBox.Text = this.hat.ReadAnalog(GIS.FEZHAT.AnalogPin.Ain1).ToString("N2");
                */
                if (isNavigating) return;
                isNavigating = true;
                this.hat.D2.Color = GIS.FEZHAT.Color.Black;
                this.hat.D3.Color = GIS.FEZHAT.Color.Black;

                switch (Mobil.Arah)
                {
                    case MobilRemote.ArahJalan.Maju:
                        this.hat.MotorA.Speed = 1.0;
                        this.hat.MotorB.Speed = 1.0;
                        this.hat.D2.Color = GIS.FEZHAT.Color.Green;
                        this.hat.D3.Color = GIS.FEZHAT.Color.Green;
                        break;
                    case MobilRemote.ArahJalan.Mundur:
                        this.hat.MotorA.Speed = -1.0;
                        this.hat.MotorB.Speed = -1.0;
                        this.hat.D2.Color = GIS.FEZHAT.Color.Yellow;
                        this.hat.D3.Color = GIS.FEZHAT.Color.Yellow;
                        break;
                    case MobilRemote.ArahJalan.Kiri:
                        this.hat.MotorA.Speed = -0.7;
                        this.hat.MotorB.Speed = 0.7;
                        this.hat.D2.Color = GIS.FEZHAT.Color.Blue;
                        this.hat.D3.Color = GIS.FEZHAT.Color.Blue;
                        break;
                    case MobilRemote.ArahJalan.Kanan:
                        this.hat.MotorB.Speed = -0.7;
                        this.hat.MotorA.Speed = 0.7;
                        this.hat.D2.Color = GIS.FEZHAT.Color.Cyan;
                        this.hat.D3.Color = GIS.FEZHAT.Color.Cyan;
                        break;
                    case MobilRemote.ArahJalan.Stop:
                        this.hat.MotorA.Speed = 0.0;
                        this.hat.MotorB.Speed = 0.0;
                        this.hat.D2.Color = GIS.FEZHAT.Color.Red;
                        this.hat.D3.Color = GIS.FEZHAT.Color.Red;
                        break;
                        
                }
                isNavigating = false;
            };
            timer.Start();
          
            client = new MqttClient(MQTT_BROKER_ADDRESS);
            string clientId = Guid.NewGuid().ToString();
            client.Connect(clientId);
            SubscribeMessage();
        }