Toolbox.NETMF.Hardware.HBridge


Toolbox.NETMF.Hardware.HBridge(Speed1, Direction1, Speed2, Direction2)
  • Speed1 Motor 1 PWM control pin
  • Direction1 Motor 1 Direction control pin
  • Speed2 Motor 2 PWM control pin
  • Direction2 Motor 2 Direction control pin

Methods

  • SetState(Motor, Speed) Sets the speed from one of the motors (negative values are backwards)
  • Dispose() Cleans up the object, releasing all pins

How to connect

Toolbox_NETMF_Hardware_HBridge.png

Sample code in C#

// Defines the HBridge IC on the correct pins
HBridge MotorDriver = new HBridge(new Netduino.PWM(Pins.GPIO_PIN_D6), Pins.GPIO_PIN_D7, new Netduino.PWM(Pins.GPIO_PIN_D5), Pins.GPIO_PIN_D4);

// Motor 1 half speed backward
MotorDriver.SetState(HBridge.Motors.Motor1, -50);
// Motor 2 half speed forward
MotorDriver.SetState(HBridge.Motors.Motor2, 50);

// Lets run for 5 seconds
Thread.Sleep(5000);

// Motor 1 full speed backward
MotorDriver.SetState(HBridge.Motors.Motor1, -100);
// Motor 2 full speed forward
MotorDriver.SetState(HBridge.Motors.Motor2, 100);

// Lets run for 5 seconds
Thread.Sleep(5000);

// Stops both motors
MotorDriver.SetState(HBridge.Motors.Motor1, 0);
MotorDriver.SetState(HBridge.Motors.Motor2, 0);

Sample code in VB

' Defines the HBridge IC on the correct pins
Dim MotorDriver As HBridge = New HBridge(new Netduino.PWM(Pins.GPIO_PIN_D6), Pins.GPIO_PIN_D7, new Netduino.PWM(Pins.GPIO_PIN_D5), Pins.GPIO_PIN_D4)

' Motor 1 half speed backward
MotorDriver.SetState(HBridge.Motors.Motor1, -50)
' Motor 2 half speed forward
MotorDriver.SetState(HBridge.Motors.Motor2, 50)

' Lets run for 5 seconds
Thread.Sleep(5000)

' Motor 1 full speed backward
MotorDriver.SetState(HBridge.Motors.Motor1, -100)
' Motor 2 full speed forward
MotorDriver.SetState(HBridge.Motors.Motor2, 100)

' Lets run for 5 seconds
Thread.Sleep(5000)

' Stops both motors
MotorDriver.SetState(HBridge.Motors.Motor1, 0)
MotorDriver.SetState(HBridge.Motors.Motor2, 0)

Related documents

Last edited Jan 1, 2013 at 7:07 PM by Garrcomm, version 4