From bcb2047f604ccf2b525dd0896b07d9bb2f8ee80e Mon Sep 17 00:00:00 2001 From: Zvonimir Rudinski Date: Tue, 28 Apr 2026 19:18:32 +0200 Subject: [PATCH] fix(joystick): add offsets --- include/joystick.hpp | 3 +++ src/joystick.cpp | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/joystick.hpp b/include/joystick.hpp index 6ee592c..441089b 100644 --- a/include/joystick.hpp +++ b/include/joystick.hpp @@ -25,4 +25,7 @@ class Joystick { uint8_t vrx; uint8_t vry; uint8_t sw; + + const uint8_t xOffset = 13; + const uint8_t yOffset = 10; }; diff --git a/src/joystick.cpp b/src/joystick.cpp index 0d9b39f..98a482a 100644 --- a/src/joystick.cpp +++ b/src/joystick.cpp @@ -9,11 +9,11 @@ Joystick::Joystick() : vrx(A0), vry(A1), sw(4) { // Map the analog readings from the joystick to a range of -100 to 100 for both X and Y axes double Joystick::getX() const { - return map(analogRead(vrx), 0, 1023, -100, 100); + return map(analogRead(vrx), 0, 1023, -100, 100) + xOffset; } double Joystick::getY() const { - return map(analogRead(vry), 0, 1023, -100, 100); + return map(analogRead(vry), 0, 1023, -100, 100) + yOffset; } // Check if the joystick button is pressed (active LOW)