static void PWMFanSimpleExample() { Console.WriteLine("Starting PWM Controller - Simple Demo"); using (var controller = new PwmController()) { double dutyCycle = 100; var chip = 0; var channel = 0; var hertz = 25; controller.OpenChannel(chip, channel); controller.StartWriting(chip, channel, hertz, dutyCycle); Console.WriteLine("Duty cycle " + dutyCycle); Task.Delay(new TimeSpan(0, 0, 10)).Wait(); //10 second wait to give fan time to power up ReadTachometer(); dutyCycle = 70; controller.ChangeDutyCycle(chip, channel, dutyCycle); Console.WriteLine("Duty cycle " + dutyCycle); Task.Delay(new TimeSpan(0, 0, 2)).Wait(); //2 second wait ReadTachometer(); dutyCycle = 30; controller.ChangeDutyCycle(chip, channel, dutyCycle); Console.WriteLine("Duty cycle " + dutyCycle); Task.Delay(new TimeSpan(0, 0, 2)).Wait(); //2 second wait ReadTachometer(); controller.ChangeDutyCycle(chip, channel, 0); // controller.StopWriting(chip, channel); controller.CloseChannel(chip, channel); Console.WriteLine("Finished - Simple Demo"); } }
static void Main(string[] args) { Console.WriteLine("Hello PWM!"); var PwmController = new PwmController(new SoftPwm()); PwmController.OpenChannel(17, 0); PwmController.StartWriting(17, 0, 200, 0); while (true) { for (int i = 0; i < 100; i++) { PwmController.ChangeDutyCycle(17, 0, i); Thread.Sleep(100); } } }
/// <summary> /// Rotate the servomotor with a specific pulse in microseconds /// </summary> /// <param name="durationMicroSec">Pulse duration in microseconds</param> public void SetPulse(uint durationMicroSec) { _currentPulseWidth = durationMicroSec / 1000.0; _pwmController.ChangeDutyCycle(_servoPin, _pwmChannel, (1 - (_pulseFrequency - _currentPulseWidth) / _pulseFrequency) * 100); }
private void SetPwmFill(double fill) { _pwm.ChangeDutyCycle(_chip, _channel, fill * 100.0); }