private void SetColor(uint colorCode)
 {
     Debug.WriteLine("Setting color to: " + colorCode);
     _colorPin0.Write((colorCode & 1) == 1);
     _colorPin1.Write((colorCode & 2) == 2);
     _colorPin2.Write((colorCode & 4) == 4);
     _colorPin3.Write((colorCode & 8) == 8);
 }
Example #2
0
 private void SetColor(uint colorCode)
 {
     if (_isOn)
     {
         Debug.WriteLine("Setting color to: " + colorCode);
         _colorPin0.Write((colorCode & 1) == 1);
         _colorPin1.Write((colorCode & 2) == 2);
         _colorPin2.Write((colorCode & 4) == 4);
         _colorPin3.Write((colorCode & 8) == 8);
     }
     else
     {
         Debug.WriteLine("Turning off LED strip.");
         _colorPin0.Write(false);
         _colorPin1.Write(false);
         _colorPin2.Write(false);
         _colorPin3.Write(false);
     }
     _colorCode = colorCode;
 }
        private async void Setup()
        {
            this.mainboard = await GT.Module.CreateAsync <GTMB.FEZCream>();

            this.motor = await GT.Module.CreateAsync <GTMO.MotorDriverL298>(this.mainboard.GetProvidedSocket(8));

            this.breakout = await GT.Module.CreateAsync <GTMO.BreakoutTB10>(this.mainboard.GetProvidedSocket(4));

            this.RedLed = await breakout.CreateDigitalIOAsync(GHIElectronics.UWP.GadgeteerCore.SocketPinNumber.Eight, false);

            this.GreenLed = await breakout.CreateDigitalIOAsync(GHIElectronics.UWP.GadgeteerCore.SocketPinNumber.Nine, false);

            this.Buzz = await breakout.CreateDigitalIOAsync(GHIElectronics.UWP.GadgeteerCore.SocketPinNumber.Seven, false);

            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.motor.SetSpeed(GHIElectronics.UWP.Gadgeteer.Modules.MotorDriverL298.Motor.Motor1, 1.0);
                    this.motor.SetSpeed(GHIElectronics.UWP.Gadgeteer.Modules.MotorDriverL298.Motor.Motor2, 1.0);

                    GreenLed.Write(true);
                    RedLed.Write(false);
                    Buzz.Write(false);
                    break;

                case MobilRemote.ArahJalan.Mundur:
                    this.motor.SetSpeed(GHIElectronics.UWP.Gadgeteer.Modules.MotorDriverL298.Motor.Motor1, -1.0);
                    this.motor.SetSpeed(GHIElectronics.UWP.Gadgeteer.Modules.MotorDriverL298.Motor.Motor2, -1.0);

                    GreenLed.Write(false);
                    RedLed.Write(true);
                    Buzz.Write(false);

                    break;

                case MobilRemote.ArahJalan.Kiri:
                    this.motor.SetSpeed(GHIElectronics.UWP.Gadgeteer.Modules.MotorDriverL298.Motor.Motor1, -0.7);
                    this.motor.SetSpeed(GHIElectronics.UWP.Gadgeteer.Modules.MotorDriverL298.Motor.Motor2, 0.7);

                    GreenLed.Write(false);
                    RedLed.Write(false);
                    Buzz.Write(false);
                    break;

                case MobilRemote.ArahJalan.Kanan:
                    this.motor.SetSpeed(GHIElectronics.UWP.Gadgeteer.Modules.MotorDriverL298.Motor.Motor1, 0.7);
                    this.motor.SetSpeed(GHIElectronics.UWP.Gadgeteer.Modules.MotorDriverL298.Motor.Motor2, -0.7);

                    GreenLed.Write(false);
                    RedLed.Write(false);
                    Buzz.Write(false);
                    break;

                case MobilRemote.ArahJalan.Stop:
                    this.motor.SetSpeed(GHIElectronics.UWP.Gadgeteer.Modules.MotorDriverL298.Motor.Motor1, 0.0);
                    this.motor.SetSpeed(GHIElectronics.UWP.Gadgeteer.Modules.MotorDriverL298.Motor.Motor2, 0.0);

                    GreenLed.Write(false);
                    RedLed.Write(false);
                    Buzz.Write(false);
                    break;
                }
                isNavigating = false;
            };
            timer.Start();

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

            client.Connect(clientId);
            SubscribeMessage();
        }