1. 테스크를 병렬로 사용한다
Task.WaitAll(
Task.Factory.StartNew(()=>DoSomething()),
Task.Factory.StartNew(()=>Thread.Sleep(200))
);
2.스톱워치 사용 : 매우 정확함. 스톱워치 시작, 작업, 대기 ->
private void Wait(double milliseconds)
{
long initialTick = stopwatch.ElapsedTicks;
long initialElapsed = stopwatch.ElapsedMilliseconds;
double desiredTicks = milliseconds / 1000.0 * Stopwatch.Frequency;
double finalTick = initialTick + desiredTicks;
while (stopwatch.ElapsedTicks < finalTick)
{
}
}
private void btnRight_Click(object sender, RoutedEventArgs e)
{
currentPulseWidth = 0;
//The stopwatch will be used to precisely time calls to pulse the motor.
stopwatch = Stopwatch.StartNew();
GpioController controller = GpioController.GetDefault();
servoPin = controller.OpenPin(13);
servoPin.SetDriveMode(GpioPinDriveMode.Output);
// Here is how you would move the motor. Call a funciton like this when ever you are ready to move motor
MoveMotor(ForwardPulseWidth);
Wait(3000); //wait three seconds
//move it backwards
MoveMotor(BackwardPulseWidth);
}
댓글 없음:
댓글 쓰기