feat(joystick): add joystick class
This commit is contained in:
@@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user