public static void Main()
        {
            var latch  = new OutputPort(Pins.GPIO_PIN_D12, false);
            var enable = new OutputPort(Pins.GPIO_PIN_D7, true);
            var data   = new OutputPort(Pins.GPIO_PIN_D8, false);
            var clock  = new OutputPort(Pins.GPIO_PIN_D4, false);
            var adafruitMotorShieldV1 = new AdafruitV1MotorShield(latch, enable, data, clock);

            adafruitMotorShieldV1.InitializeShield();
            servo1         = adafruitMotorShieldV1.GetServoMotor(1);
            servo1Position = 0;
            timer          = new Timer(SetServoPosition, null, 40, 40);
            Thread.Sleep(Timeout.Infinite);
            var dummy = 0;
        }
예제 #2
0
        public static void Main()
        {
            // shield-specific setup. Uncomment one of the shield #define lines above.
#if UseOnboardLedForDiagnostics
            Led = new OutputPort(Pins.ONBOARD_LED, false);
#endif
            HBridge bridge1;
            HBridge bridge2;
#if AdafruitV1Shield
            var shield = new AdafruitV1MotorShield();
            shield.InitializeShield();
            bridge1 = shield.GetDcMotor(1);
            bridge2 = shield.GetDcMotor(2);
#elif AdafruitV2Shield
            var shield = new AdafruitV2MotorShield();
            shield.InitializeShield();
            bridge1 = shield.GetDcMotor(1);
            bridge2 = shield.GetDcMotor(2);
#elif SparkfunArduMotoShield
            var shield = new SparkfunArdumoto();
            shield.InitializeShield();
            bridge1 = shield.GetHBridge(Connector.A, TargetDevice.Netduino);
            bridge2 = shield.GetHBridge(Connector.B, TargetDevice.Netduino);
#elif LedSimulatorShield
            bridge1 = LedMotorSimulator.GetDcMotor(Pins.GPIO_PIN_D0, PWMChannels.PWM_ONBOARD_LED);
            bridge2 = LedMotorSimulator.GetDcMotor(Pins.GPIO_PIN_D1, PWMChannels.PWM_PIN_D6);
#else
            throw new ApplicationException("Uncomment one of the shield #define statements");
#endif

            // Create the stepper motor axes and link them to the Adafruit driver.
            var motor1 = new DcMotor(bridge1);
            var motor2 = new DcMotor(bridge2);
            while (true)
            {
                var targetSpeed1 = randomGenerator.NextDouble() / 2.0 + 0.5; // range -1.0 to +1.0
                var targetSpeed2 = randomGenerator.NextDouble() * 2.0 - 1.0; // range -1.0 to +1.0
                motor1.AccelerateToVelocity(targetSpeed1);
                motor2.AccelerateToVelocity(targetSpeed2);
                Thread.Sleep(6000);
            }
        }
예제 #3
0
        public static void Main()
        {
            // shield-specific setup. Uncomment one of the shield #define lines above.
#if UseOnboardLedForDiagnostics
            Led = new OutputPort(Pins.ONBOARD_LED, false);
#endif
#if AdafruitV1Shield
            var latch  = new OutputPort(Pins.GPIO_PIN_D12, false);
            var enable = new OutputPort(Pins.GPIO_PIN_D7, true);
            var data   = new OutputPort(Pins.GPIO_PIN_D8, false);
            var clock  = new OutputPort(Pins.GPIO_PIN_D4, false);
            var adafruitMotorShieldV1 = new AdafruitV1MotorShield(latch, enable, data, clock);
            adafruitMotorShieldV1.InitializeShield();
            StepperM1M2 = adafruitMotorShieldV1.GetMicrosteppingStepperMotor(MicrostepsPerStep, 1, 2);
            //StepperM3M4 = adafruitMotorShieldV1.GetMicrosteppingStepperMotor(MicrostepsPerStep, 3, 4);
#elif AdafruitV2Shield
            var adafruitMotorShieldV2 = new SparkfunArdumoto();  // use shield at default I2C address.
            adafruitMotorShieldV2.InitializeShield();
            StepperM1M2 = adafruitMotorShieldV2.GetMicrosteppingStepperMotor(MicrostepsPerStep, 1, 2);
            StepperM3M4 = adafruitMotorShieldV2.GetMicrosteppingStepperMotor(MicrostepsPerStep, 3, 4);
#elif SparkfunArduMotoShield
            var shield = new SparkfunArdumoto();
            shield.InitializeShield();
            var phase1 = shield.GetHBridge(Connector.A, TargetDevice.Netduino);
            var phase2 = shield.GetHBridge(Connector.B, TargetDevice.Netduino);
            StepperM1M2 = shield.GetMicrosteppingStepperMotor(MicrostepsPerStep, phase1, phase2);
#elif LedSimulatorShield
            var StepperM1M2 = LedMotorSimulator.GetSimulatedStepperMotor(Pins.GPIO_PIN_D0,
                                                                         PWMChannels.PWM_ONBOARD_LED,
                                                                         Pins.GPIO_PIN_D1,
                                                                         PWMChannels.PWM_PIN_D6);
            var StepperM3M4 = LedMotorSimulator.GetSimulatedStepperMotor(Pins.GPIO_PIN_D2,
                                                                         PWMChannels.PWM_PIN_D9,
                                                                         Pins.GPIO_PIN_D3,
                                                                         PWMChannels.PWM_PIN_D10);
#else
            throw new ApplicationException("Uncomment one of the shield #define statements");
#endif

            // Create the stepper motor axes and link them to the Adafruit driver.
            var axis1 = new AcceleratingStepperMotor(LimitOfTravel, StepperM1M2)
            {
                MaximumSpeed = MaxSpeed,
                RampTime     = RampTime
            };
            // Now we subscribe to the MotorStopped event on each axis. When the event fires,
            // we start the axis going again with a new random target position.
            axis1.MotorStopped += HandleAxisStoppedEvent;
            // We need to call our event handler once manually to get things going.
            // After that it is fully automatic.
            HandleAxisStoppedEvent(axis1);

            // Repeat for the second axis, if it's supported.
#if UseSecondAxis
            //var axis2 = new StepperMotor(LimitOfTravel, StepperM3M4)
            //    {
            //    MaximumSpeed = MaxSpeed,
            //    RampTime = RampTime
            //    };
            //axis2.MotorStopped += HandleAxisStoppedEvent;
            //HandleAxisStoppedEvent(axis2);
#endif

            // Finally, we sleep forever as there is nothing else to do in the main thread.
            // The motors continue to work in the background all by themselves.
            Thread.Sleep(Timeout.Infinite);
        }
예제 #4
0
        public static void Main()
        {
            // shield-specific setup. Uncomment one of the shield #define lines above.
#if UseOnboardLedForDiagnostics
            Led = new OutputPort(Pins.ONBOARD_LED, false);
#endif
#if AdafruitV1Shield
            var adafruitMotorShieldV1 = new AdafruitV1MotorShield();
            adafruitMotorShieldV1.InitializeShield();
            StepperM1M2 = adafruitMotorShieldV1.GetMicrosteppingStepperMotor(MicrostepsPerStep, 1, 2);
            StepperM3M4 = adafruitMotorShieldV1.GetFullSteppingStepperMotor(3, 4);
#elif AdafruitV2Shield
            var adafruitMotorShieldV2 = new SparkfunArdumoto();  // use shield at default I2C address.
            adafruitMotorShieldV2.InitializeShield();
            StepperM1M2 = adafruitMotorShieldV2.GetMicrosteppingStepperMotor(MicrostepsPerStep, 1, 2);
            StepperM3M4 = adafruitMotorShieldV2.GetMicrosteppingStepperMotor(MicrostepsPerStep, 3, 4);
#elif SparkfunArduMotoShield
            var shield = new SparkfunArdumoto();
            shield.InitializeShield();
            var phase1 = shield.GetHBridge(Connector.A, TargetDevice.Netduino);
            var phase2 = shield.GetHBridge(Connector.B, TargetDevice.Netduino);
            StepperM1M2 = shield.GetMicrosteppingStepperMotor(MicrostepsPerStep, phase1, phase2);
#elif LedSimulatorShield
            var StepperM1M2 = LedMotorSimulator.GetSimulatedStepperMotor(Pins.GPIO_PIN_D0,
                                                                         PWMChannels.PWM_ONBOARD_LED,
                                                                         Pins.GPIO_PIN_D1,
                                                                         PWMChannels.PWM_PIN_D6);
#else
            throw new ApplicationException("Uncomment one of the shield #define statements");
#endif

            // Create the stepper motor axes and link them to the shield driver.
            axis1 = new InstantaneousStepperMotor(LimitOfTravel, StepperM1M2)
            {
                MaximumSpeed = MaxSpeed
                               //RampTime = RampTime
            };

            axis1.BeforeStep += UpdateDiagnosticLed;

            speed     = 1.0;
            direction = +1;

            var fasterButton = new InterruptPort(Pins.GPIO_PIN_D1,
                                                 true,
                                                 Port.ResistorMode.PullUp,
                                                 Port.InterruptMode.InterruptEdgeLow);
            var slowerButton = new InterruptPort(Pins.GPIO_PIN_D2,
                                                 true,
                                                 Port.ResistorMode.PullUp,
                                                 Port.InterruptMode.InterruptEdgeLow);
            var reverseButton = new InterruptPort(Pins.GPIO_PIN_D13,
                                                  true,
                                                  Port.ResistorMode.PullUp,
                                                  Port.InterruptMode.InterruptEdgeLow);
            fasterButton.OnInterrupt  += fasterButton_OnInterrupt;
            slowerButton.OnInterrupt  += slowerButton_OnInterrupt;
            reverseButton.OnInterrupt += reverseButton_OnInterrupt;
            SetMotorVelocity();
            Thread.Sleep(Timeout.Infinite);
        }