feat(joystick): add joystick class

This commit is contained in:
2026-04-24 15:29:45 +02:00
parent 51cbbd35e8
commit d5e5f031da
2 changed files with 50 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
#pragma once
#include <Arduino.h>
/*
* A helper class to read values from the KY-023 joystick module.
* It provides methods to get the X and Y positions of the joystick, as well as whether the button is pressed.
* The joystick is connected to the following pins:
* - VRx (X-axis) connected to A0
* - VRy (Y-axis) connected to A1
* - SW (button) connected to D4
*
* Note: The button is active LOW and requires a pull-up resistor, which can either be external (10kΩ)
* or the internal pull-up resistor of the microcontroller (default).
*
* TODO: Add "deadzone" handling to prevent small joystick movements from being registered as input.
*/
class Joystick {
public:
Joystick();
double getX() const;
double getY() const;
bool isPressed() const;
private:
uint8_t vrx;
uint8_t vry;
uint8_t sw;
};