private async Task RunMotorSyncTime(BrickPortMotor[] ports, int[] speeds, int timeout)
{
if ((ports == null) || (speeds == null))
return;
if (ports.Length != speeds.Length)
return;
//create a timer for the needed time to run
if (timer == null)
timer = new Timer(RunUntil, ports, TimeSpan.FromMilliseconds(timeout), Timeout.InfiniteTimeSpan);
else
timer.Change(TimeSpan.FromMilliseconds(timeout), Timeout.InfiniteTimeSpan);
//initialize the speed and enable motors
for(int i=0; i<ports.Length; i++)
{
StartMotor((int)ports[i], speeds[i]);
}
bool nonstop = true;
while(nonstop)
{
bool status = false;
for (int i=0; i<ports.Length;i++)
{
status |= IsRunning(ports[i]);
}
nonstop = status;
}
}