static async void Blink(GpioPinWrapper Pin, int WaitTime, CancellationToken cancellationToken) { bool CurrentValue = false; while (!cancellationToken.IsCancellationRequested) { Pin.Status = CurrentValue ? GpioPinValue.High : GpioPinValue.Low; CurrentValue = !CurrentValue; await Task.Delay(TimeSpan.FromSeconds(WaitTime)); } }
public static async Task <GameManager> CreateAsync() { var commandInterpreterConstructor = CommandInterpreter.CreateAsync(); ChessLogic logic = new ChessLogic(); var stepCountPinX = new GpioPinWrapper(5, Windows.Devices.Gpio.GpioPinDriveMode.InputPullUp); var stepClearPinX = new GpioPinWrapper(13, Windows.Devices.Gpio.GpioPinDriveMode.Output, Windows.Devices.Gpio.GpioPinValue.Low); var motorInformationX = new MotorInformation(Axis.X, stepCountPinX); var motorDriverX = new MotorDrv(20, 21, motorInformationX); var motorLocatorX = new MotorLocator(stepClearPinX, motorDriverX.Information); var positionSignalerX = new PositionSignaler(motorLocatorX); var motorMoverX = new MotorMover(50, positionSignalerX, motorLocatorX, motorDriverX); var stepCountPinY = new GpioPinWrapper(6, Windows.Devices.Gpio.GpioPinDriveMode.InputPullUp); var stepClearPinY = new GpioPinWrapper(19, Windows.Devices.Gpio.GpioPinDriveMode.Output, Windows.Devices.Gpio.GpioPinValue.Low); var motorInformationY = new MotorInformation(Axis.Y, stepCountPinY); var motorDriverY = new MotorDrv(24, 23, motorInformationY); var motorLocatorY = new MotorLocator(stepClearPinY, motorDriverY.Information); var positionSignalerY = new PositionSignaler(motorLocatorY); var motorMoverY = new MotorMover(50, positionSignalerY, motorLocatorY, motorDriverY); var topInterrupterX = new PhotoInterrupter(17, 1, 150); var bottomInterrupterX = new PhotoInterrupter(27, -1, -150); var motorCalibratorX = new MotorCalibrator(-23, 23, motorMoverX, motorInformationX, topInterrupterX, bottomInterrupterX); var topInterrupterY = new PhotoInterrupter(25, 1, 150); var bottomInterrupterY = new PhotoInterrupter(22, -1, -150); var motorCalibratorY = new MotorCalibrator(-17, 17, motorMoverY, motorInformationY, topInterrupterY, bottomInterrupterY); var preciseMoverX = new PreciseMotorMover(motorMoverX); var gridMoverX = new GridMotorMover(preciseMoverX, motorCalibratorX); var preciseMoverY = new PreciseMotorMover(motorMoverY); var gridMoverY = new GridMotorMover(preciseMoverY, motorCalibratorY); var magnetDriver = new MagnetDrv(26); var movePerformer = new MovePerformer(gridMoverX, gridMoverY, magnetDriver); var motorCalibrationTask = movePerformer.CalibrateAsync(); var movePlanner = new MovePlanner(logic.Board); var moveManager = new MoveManager(movePlanner, movePerformer); GameManager manager = new GameManager(await commandInterpreterConstructor, logic, moveManager); await motorCalibrationTask; #if DEBUG manager.DebugMovePerformer = movePerformer; #endif return(manager); }
static async void PWM(GpioPinWrapper Pin, uint time, CancellationToken cancellationToken) { Pin.Status = GpioPinValue.High; int pwm_time_high = (int)time; int pwm_time_low = (int)(10 - time); while (!cancellationToken.IsCancellationRequested) { Pin.Pin.Write(GpioPinValue.High); await Task.Delay(pwm_time_high); Pin.Pin.Write(GpioPinValue.Low); await Task.Delay(pwm_time_low); } Pin.Status = GpioPinValue.Low; }
void Server_NewQueryAppeared(object sender, string e) { if (e == null || e == "") { return; } string message = e.ToLower(); GpioPinValue newValue = GpioPinValue.High; GpioPinWrapper LED = null; if (message.Contains("on")) { newValue = GpioPinValue.High; } else if (message.Contains("off")) { newValue = GpioPinValue.Low; } if (message.Contains("red")) { LED = PinLED1; } else if (message.Contains("green")) { LED = PinLED2; } else if (message.Contains("white")) { return; } else if (message.Contains("white")) { return; } LED.Status = newValue; }