Toolbox.NETMF.Hardware.AdafruitMotorshield

Toolbox.NETMF.Hardware.AdafruitMotorshield(ClockPin, EnablePin, DataPin, LatchPin, Motor1Pwm, Motor2Pwm, Motor3Pwm, Motor4Pwm)
  • ClockPin SPI Clock pin
  • EnablePin SPI Enable pin
  • DataPin SPI Data pin
  • LatchPin SPI Latch pin
  • Motor1Pwm Motor 1 PWM pin
  • Motor2Pwm Motor 2 PWM pin
  • Motor3Pwm Motor 3 PWM pin
  • Motor4Pwm Motor 4 PWM pin

Methods

  • SetState(Motor, Speed) Sets the speed from one of the motors (negative values are backwards)
  • Dispose() Disposes the AdafruitMotorshield object

Sample code in C#

/*
 * This constructor works perfectly for the Netduino Go! Shield Base.
 * If you're using a Netduino Classic or Plus, you can drive just two motors.
 * To keep the code working, use null for Motor1Pwm and Motor2Pwm.
 */
AdafruitMotorshield Shield = new AdafruitMotorshield(
    // The bitbanged SPI bus for the DC Motor A/B pins
    ClockPin: Pins.GPIO_PIN_D4,
    EnablePin: Pins.GPIO_PIN_D7,
    DataPin: Pins.GPIO_PIN_D8,
    LatchPin: Pins.GPIO_PIN_D12,
    // DC Motor PWM pins
    //Motor1Pwm: new Netduino.PWM(Pins.GPIO_PIN_D11), // Use null if you're using a Netduino Classic or Plus
    //Motor2Pwm: new Netduino.PWM(Pins.GPIO_PIN_D3),  // Use null if you're using a Netduino Classic or Plus
    Motor1Pwm: null,
    Motor2Pwm: null,
    Motor3Pwm: new Netduino.PWM(Pins.GPIO_PIN_D6),
    Motor4Pwm: new Netduino.PWM(Pins.GPIO_PIN_D5)
);

while (true)
{
    for (sbyte i = -100; i < 100; ++i)
    {
        Shield.SetState(AdafruitMotorshield.Motors.Motor4, i);
        Thread.Sleep(100);
    }
    for (sbyte i = 99; i > -100; --i)
    {
        Shield.SetState(AdafruitMotorshield.Motors.Motor4, i);
        Thread.Sleep(100);
    }
}

Sample code in VB

' This constructor works perfectly for the Netduino Classic and Plus,
' but if you're using a Netduino Classic or Plus, you can drive just two motors.
' So to keep the code working, I used null for Motor1Pwm and Motor2Pwm.
Dim Shield As AdafruitMotorshield = New AdafruitMotorshield(
                                    ClockPin:=Pins.GPIO_PIN_D4,
                                    EnablePin:=Pins.GPIO_PIN_D7,
                                    DataPin:=Pins.GPIO_PIN_D8,
                                    LatchPin:=Pins.GPIO_PIN_D13,
                                    Motor1Pwm:=Nothing,
                                    Motor2Pwm:=Nothing,
                                    Motor3Pwm:=New Netduino.PWM(Pins.GPIO_PIN_D6),
                                    Motor4Pwm:=New Netduino.PWM(Pins.GPIO_PIN_D5)
)

Do
    For i As SByte = -100 To 100 Step 1
        Shield.SetState(AdafruitMotorshield.Motors.Motor4, i)
        Thread.Sleep(100)
    Next
    For i As SByte = 99 To -99 Step -1
        Shield.SetState(AdafruitMotorshield.Motors.Motor4, i)
        Thread.Sleep(100)
    Next
Loop

Last edited Jun 2, 2012 at 7:23 PM by Garrcomm, version 1