コード例 #1
0
ファイル: Program.cs プロジェクト: TjWheeler/dotnet-iot-demos
        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");
            }
        }
コード例 #2
0
    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);
            }
        }
    }
コード例 #3
0
 /// <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);
 }
コード例 #4
0
ファイル: DCMotor3Pin.cs プロジェクト: webmote/iot
 private void SetPwmFill(double fill)
 {
     _pwm.ChangeDutyCycle(_chip, _channel, fill * 100.0);
 }