public static void Run() { using (var j = new SenseHatJoystick()) { while (true) { j.Read(); Console.Clear(); if (j.HoldingUp) { Console.Write("U"); } if (j.HoldingDown) { Console.Write("D"); } if (j.HoldingLeft) { Console.Write("L"); } if (j.HoldingRight) { Console.Write("R"); } if (j.HoldingButton) { Console.Write("!"); } } } }
private void StartTask() { while (_isRunning) { _joyStick.Read(); if (_joyStick.HoldingDown || _joyStick.HoldingUp || _joyStick.HoldingLeft || _joyStick.HoldingRight) { if (_joyStick.HoldingDown && _joyStick.HoldingUp) { continue; } if (_joyStick.HoldingLeft && _joyStick.HoldingRight) { continue; } lastState = new JoystickState { Down = _joyStick.HoldingDown, Up = _joyStick.HoldingUp, Left = _joyStick.HoldingLeft, Right = _joyStick.HoldingRight, }; } else if (_joyStick.HoldingButton) { lastState = new JoystickState { Clicked = true }; } Task.Delay(_refreshRate).Wait(); } }