MotorWing motorWing;
public override Task Initialize()
{
Console.WriteLine("Initializing ...");
var i2CBus = Device.CreateI2cBus(I2cBusSpeed.FastPlus);
motorWing = new MotorWing(i2CBus, new Frequency(100, Frequency.UnitType.Hertz), 0x61);
motorWing.Initialize();
return Task.CompletedTask;
}
public override async Task Run()
{
var dcMotor1 = motorWing.GetMotor(1);
var dcMotor2 = motorWing.GetMotor(2);
var stepper = motorWing.GetStepper(2, 200);
dcMotor1.Run(Commmand.FORWARD);
dcMotor2.Run(Commmand.BACKWARD);
while (true)
{
Console.WriteLine("Speed up");
for (short i = 0; i <= 255; i++)
{
dcMotor1.SetSpeed(i);
dcMotor2.SetSpeed(i);
await Task.Delay(10);
}
stepper.Step(50);
await Task.Delay(500);
Console.WriteLine("Slow down");
for (short i = 255; i >= 0; i--)
{
dcMotor1.SetSpeed(i);
dcMotor2.SetSpeed(i);
await Task.Delay(10);
}
stepper.Step(-50);
await Task.Delay(500);
}
}