Exemple #1
0
        public static void Main()
        {
            Debug.WriteLine("devMobile.Longboard starting");
            Debug.WriteLine($"I2C:{I2cDevice.GetDeviceSelector()}");
            Debug.WriteLine($"PWM:{PwmController.GetDeviceSelector()}");

            try
            {
                Debug.WriteLine("LED Starting");
                GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('A', 10));
                led.SetDriveMode(GpioPinDriveMode.Output);
                led.Write(GpioPinValue.Low);

                Debug.WriteLine("LED Starting");
                WiiNunchuk nunchuk = new WiiNunchuk("I2C1");

                Debug.WriteLine("ESC Starting");
                PwmController pwm    = PwmController.FromId("TIM5");
                PwmPin        pwmPin = pwm.OpenPin(PinNumber('A', 1));
                pwmPin.Controller.SetDesiredFrequency(PulseFrequency);
                pwmPin.Start();

                Debug.WriteLine("Thread.Sleep Starting");
                Thread.Sleep(2000);

                Debug.WriteLine("Mainloop Starting");
                while (true)
                {
                    nunchuk.Read();

                    double duration = Map(nunchuk.AnalogStickY, WiiNunchukYMinimum, WiiNunchukYMaximum, PulseDurationMinimum, PulseDurationMaximum);
                    Debug.WriteLine($"Value:{nunchuk.AnalogStickY} Duration:{duration:F3}");

                    pwmPin.SetActiveDutyCyclePercentage(duration);

                    led.Toggle();
                    Thread.Sleep(ThrottleUpdatePeriod);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Exemple #2
0
        public static void Main()
        {
            WiiNunchuk Nunchuk = new WiiNunchuk();

            while (true)
            {
                // Reads all values
                Nunchuk.Read();

                // Prints out all values
                string Output = "Analog stick: " + Nunchuk.AnalogStickX.ToString() + "x" + Nunchuk.AnalogStickY.ToString();
                Output += " / Accellerometer: " + Nunchuk.AcceleroMeterX.ToString() + "x" + Nunchuk.AcceleroMeterY.ToString() + "x" + Nunchuk.AcceleroMeterZ.ToString();
                Output += " / C-Button: " + Nunchuk.ButtonC.ToString();
                Output += " / Z-Button: " + Nunchuk.ButtonZ.ToString();
                Debug.Print(Output);

                Thread.Sleep(1000);
            }
        }
Exemple #3
0
        public static void Main()
        {
            Debug.WriteLine("devMobile.Longboard.WiiNunchuckTest starting");
            Debug.WriteLine(I2cDevice.GetDeviceSelector());

            try
            {
                WiiNunchuk nunchuk = new WiiNunchuk("I2C1");

                while (true)
                {
                    nunchuk.Read();

                    Debug.WriteLine($"JoyX: {nunchuk.AnalogStickX} JoyY:{nunchuk.AnalogStickY} AX:{nunchuk.AcceleroMeterX} AY:{nunchuk.AcceleroMeterY} AZ:{nunchuk.AcceleroMeterZ} BtnC:{nunchuk.ButtonC} BtnZ:{nunchuk.ButtonZ}");

                    Thread.Sleep(100);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Exemple #4
0
        static async Task App()
        {
            board = await ConnectionService.Instance.GetFirstDeviceAsync();

            await board.ConnectAsync();

            var nunchuk = new WiiNunchuk(board.I2c);

            // Let a Poller take care of the updating
            using (var poller = new Poller <WiiNunchuk>(nunchuk))
            {
                // Hook onto some fun events
                nunchuk.JoystickChanged += Nunchuk_JoystickChanged;
                nunchuk.C.OnPressed     += C_OnPressed;
                nunchuk.Z.OnPressed     += Z_OnPressed;

                Console.WriteLine("Starting demo. Press any key to stop...");

                while (board.IsConnected && !Console.KeyAvailable)
                {
                    await Task.Delay(100);
                }
            }
        }