This library wraps the following open source project: https://github.com/adafruit/Adafruit_Motor_Shield_V2_Library
This is a beta version. Please try it and post your feedback.
DC motor example (based on their example):
Motor Stepper example:
The library is attached.
This is a beta version. Please try it and post your feedback.
DC motor example (based on their example):
B4X:
Sub Process_Globals
Public Serial1 As Serial
Private mshield As AdafruitMotorShield
Private motor As AdafruitDCMotor
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
mshield.Initialize(0x60, 1600) 'default values
motor.Initialize(mshield, 1)
motor.Speed = 150
motor.Run(motor.COMMAND_FORWARD)
motor.Run(motor.COMMAND_RELEASE)
Tick(0)
End Sub
Private Sub Tick(u As Byte)
Log("Tick")
motor.Run(motor.COMMAND_FORWARD)
SetSpeeds
Log("Tock")
motor.Run(motor.COMMAND_BACKWARD)
SetSpeeds
Log("Tech")
motor.Run(motor.COMMAND_RELEASE)
CallSubPlus("Tick", 1000, 0)
End Sub
Private Sub SetSpeeds
For i = 0 To 254
motor.Speed = i
Delay(10)
Next
For i = 255 To 1 Step - 1
motor.Speed = i
Delay(10)
Next
End Sub
Motor Stepper example:
B4X:
Sub Process_Globals
Public Serial1 As Serial
Private mshield As AdafruitMotorShield
Private stepper As AdafruitStepperMotor
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
mshield.Initialize(0x60, 1600) 'default values
stepper.Initialize(mshield, 200, 2)
stepper.Speed = 10 '10 rpm
AddLooper("Looper1")
End Sub
Private Sub Looper1
For Each style As Byte In Array As Byte(stepper.STYLE_SINGLE, stepper.STYLE_DOUBLE, stepper.STYLE_INTERLEAVE)
Log("style: ", style)
stepper.Step(100, stepper.DIR_FORWARD, style)
stepper.Step(100, stepper.DIR_BACKWARD, style)
Next
Log("microstep")
stepper.Step(50, stepper.DIR_FORWARD, stepper.STYLE_MICROSTEP)
stepper.Step(50, stepper.DIR_BACKWARD, stepper.STYLE_MICROSTEP)
End Sub
The library is attached.