예제 #1
0
        public AdafruitDCMotor GetMotor(int num)
        {
            var index = num - 1;

            if (index < 0 || index >= motors.Length)
            {
                throw new ArgumentException("Only motors 1-" + motors.Length + " are available.");
            }

            var m = motors[index];

            if (m == null)
            {
                byte pwm, in1, in2;
                switch (index)
                {
                case 0:
                    pwm = 8;
                    in2 = 9;
                    in1 = 10;
                    break;

                case 1:
                    pwm = 13;
                    in2 = 12;
                    in1 = 11;
                    break;

                case 2:
                    pwm = 2;
                    in2 = 3;
                    in1 = 4;
                    break;

                default:
                    pwm = 7;
                    in2 = 6;
                    in1 = 5;
                    break;
                }
                m             = new AdafruitDCMotor(this, pwm, in1, in2);
                motors[index] = m;
            }
            return(m);
        }
        public AdafruitDCMotor GetMotor (int num)
        {
            var index = num - 1;
            if (index < 0 || index >= motors.Length)
                throw new ArgumentException ("Only motors 1-" + motors.Length + " are available.");

            var m = motors[index];
            if (m == null) {
                byte pwm, in1, in2;
                switch (index) {
                    case 0:
                        pwm = 8;
                        in2 = 9;
                        in1 = 10;
                        break;
                    case 1:
                        pwm = 13;
                        in2 = 12;
                        in1 = 11;
                        break;
                    case 2:
                        pwm = 2;
                        in2 = 3;
                        in1 = 4;
                        break;
                    default:
                        pwm = 7;
                        in2 = 6;
                        in1 = 5;
                        break;
                }
                m = new AdafruitDCMotor (this, pwm, in1, in2);
                motors[index] = m;
            }
            return m;
        }