Esempio n. 1
0
        private static void PwmRaspiTest(RaspberryPiBoard raspi)
        {
            int pinNumber = 12; // PWM0 pin

            Console.WriteLine("Blinking and dimming an LED - Press any key to quit");
            while (!Console.KeyAvailable)
            {
                GpioController ctrl = raspi.CreateGpioController();
                ctrl.OpenPin(pinNumber);
                ctrl.SetPinMode(pinNumber, PinMode.Output);
                ctrl.Write(pinNumber, PinValue.Low);
                Thread.Sleep(500);
                ctrl.Write(pinNumber, PinValue.High);
                Thread.Sleep(1000);
                ctrl.ClosePin(pinNumber);
                ctrl.Dispose();

                var pwm = raspi.CreatePwmChannel(0, 0, 9000, 0.1);
                pwm.Start();
                for (int i = 0; i < 10; i++)
                {
                    pwm.DutyCycle = i * 0.1;
                    Thread.Sleep(500);
                }

                pwm.Stop();
                pwm.Dispose();
            }

            Console.ReadKey(true);
        }