コード例 #1
0
        private static void WritePulseWidth(PwmChannel pwmChannel, ServoMotor servoMotor)
        {
            servoMotor.Start();

            while (true)
            {
                Console.WriteLine("Enter a pulse width in microseconds ('Q' to quit). ");
                string pulseWidth = Console.ReadLine();

                if (pulseWidth.ToUpper() == "Q")
                {
                    break;
                }

                if (!int.TryParse(pulseWidth, out int pulseWidthValue))
                {
                    Console.WriteLine($"Can not parse {pulseWidth}.  Try again.");
                }

                servoMotor.WritePulseWidth(pulseWidthValue);
                Console.WriteLine($"Duty Cycle: {pwmChannel.DutyCycle * 100.0}%");
            }

            servoMotor.Stop();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: anpt1992/ConsoleAppPi
        static void WritePulseWidth(PwmChannel pwmChannel, ServoMotor servoMotor)
        {
            servoMotor.Start();
            int pulseWidthValue = 1000;

            while (true)
            {
                //Console.WriteLine("Enter a pulse width in microseconds ('Q' to quit). ");
                //string? pulseWidth = Console.ReadLine();

                //if (pulseWidth?.ToUpper() is "Q" || pulseWidth?.ToUpper() is null)
                //{
                //    break;
                //}

                //if (!int.TryParse(pulseWidth, out int pulseWidthValue))
                //{
                //    Console.WriteLine($"Can not parse {pulseWidth}.  Try again.");
                //}

                servoMotor.WritePulseWidth(pulseWidthValue);
                Console.WriteLine($"Duty Cycle: {pwmChannel.DutyCycle * 100.0}%");
                pulseWidthValue = (pulseWidthValue == 1000) ? 2000 : 1000;
                Thread.Sleep(5000);
            }

            servoMotor.Stop();
        }
コード例 #3
0
        public void Verify_Duty_Cycle_When_Writing_Pulse_Width(
            int frequency,
            int pulseWithInMicroseconds,
            double expectedDutyCycle)
        {
            Mock <PwmChannel> mockPwmChannel = new Mock <PwmChannel>();

            mockPwmChannel.SetupAllProperties();
            mockPwmChannel.Object.Frequency = frequency;
            ServoMotor servo = new ServoMotor(mockPwmChannel.Object);

            servo.WritePulseWidth(pulseWithInMicroseconds);

            Assert.Equal(expectedDutyCycle, mockPwmChannel.Object.DutyCycle, 5);
        }
コード例 #4
0
ファイル: ServoHat.cs プロジェクト: mciec/ServoHat
 /// <summary>
 /// Writes a pulse width to the servo motor.
 /// </summary>
 /// <param name="microseconds">The pulse width, in microseconds, to write to the servo motor.</param>
 public void WritePulseWidth(int microseconds) => _servoMotor.WritePulseWidth(microseconds);