コード例 #1
0
        public static void Run()
        {
            var shield = new AdafruitMotorShield();
            var robot = new TwoWheeledRobot(shield.GetMotor(1), shield.GetMotor(2));

            new SineWave(0.1, 0.5, 0.5, updateFrequency: 9).Output.ConnectTo(robot.SpeedInput);
            new SineWave(0.5, 0.333, 0, updateFrequency: 11).Output.ConnectTo(robot.DirectionInput);
        }
コード例 #2
0
        public AdafruitDCMotor(AdafruitMotorShield shield, byte pwmPin, byte in1Pin, byte in2Pin)
        {
            this.shield = shield;
            this.pwmPin = pwmPin;
            this.in1Pin = in1Pin;
            this.in2Pin = in2Pin;

            SpeedInput     = AddInput("SpeedInput", Units.Ratio);
            IsNeutralInput = AddInput("IsNeutralInput", Units.Boolean);

            SetDirection();
            SetSpeed();

            SpeedInput.ValueChanged += (s, e) => {
                var newlyReversed = SpeedInput.Value < 0;
                if (newlyReversed != isReversed)
                {
                    SetDirection();
                }

                SetSpeed();
            };
        }
コード例 #3
0
        public AdafruitDCMotor (AdafruitMotorShield shield, byte pwmPin, byte in1Pin, byte in2Pin)
        {
            this.shield = shield;
            this.pwmPin = pwmPin;
            this.in1Pin = in1Pin;
            this.in2Pin = in2Pin;

            SpeedInput = AddInput ("SpeedInput", Units.Ratio);
            IsNeutralInput = AddInput ("IsNeutralInput", Units.Boolean);
            
            SetDirection ();
            SetSpeed ();

            SpeedInput.ValueChanged += (s, e) => {

                var newlyReversed = SpeedInput.Value < 0;
                if (newlyReversed != isReversed) {
                    SetDirection ();
                }

                SetSpeed ();
            };
        }