/// <summary>
        /// Initializes a new instance of the <see cref="InfraredEmitter"/> class.
        /// </summary>
        /// <param name="outputPin">The output pin.</param>
        public InfraredEmitter(GpioPin outputPin)
        {
            if (outputPin == null || outputPin.HasCapability(PinCapability.PWM) == false)
            {
                throw new ArgumentException("Pin does not support PWM", nameof(outputPin));
            }

            OutputPin         = outputPin;
            OutputPin.PinMode = GpioPinDriveMode.PwmOutput;
            OutputPin.PwmMode = PwmMode.MarkSign;

            // Parameters taken from:
            // https://mariodivece.com/blog/2018/03/21/rpi-pwm-demystified
            OutputPin.PwmClockDivisor = 5;
            OutputPin.PwmRange        = 101;
            OutputPin.PwmRegister     = 0;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HardwareServo"/> class.
        /// </summary>
        /// <param name="outputPin">The output pin.</param>
        /// <exception cref="ArgumentException">Pin does not support PWM - outputPin.</exception>
        public HardwareServo(GpioPin outputPin)
        {
            if (outputPin == null || outputPin.HasCapability(PinCapability.PWM) == false)
            {
                throw new ArgumentException("Pin does not support PWM", nameof(outputPin));
            }

            OutputPin         = outputPin;
            OutputPin.PinMode = GpioPinDriveMode.PwmOutput;
            OutputPin.PwmMode = PwmMode.MarkSign;

            // Parameters taken from:
            // https://mariodivece.com/blog/2018/03/21/rpi-pwm-demystified
            OutputPin.PwmClockDivisor = 96;
            OutputPin.PwmRange        = 4000;
            OutputPin.PwmRegister     = 0;

            Frequency        = (double)((GpioController)Pi.Gpio).PwmBaseFrequency / OutputPin.PwmClockDivisor / OutputPin.PwmRange;
            PeriodMs         = 1d / Frequency * 1000;
            MaxPulseLengthMs = PeriodMs * 1024d / OutputPin.PwmRange;
            PulseLengthMs    = 1.0d; // default is 1ms pulses
        }