Compare commits

...

2 Commits

Author SHA1 Message Date
zvonimir b63c610665 feat(display): increase col/row number 2026-04-28 19:18:51 +02:00
zvonimir bcb2047f60 fix(joystick): add offsets 2026-04-28 19:18:32 +02:00
4 changed files with 7 additions and 4 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ An open-source implementation of the Tamagotchi virtual pet game, designed to ru
## Bill of Materials
- Arduino Nano (ATmega328P)
- KY-023 Joystick Module
- HD44780 Character LCD
- HD44780 Character LCD (20x4 or 16x2, can be changed in the code)
## Development
After cloning the repository, navigate to the project directory and run `make build` to compile the code. To upload the compiled firmware to your Arduino Nano, use `make upload`.
+1 -1
View File
@@ -7,7 +7,7 @@
*/
class Display {
public:
Display(uint8_t addr = 0x27, uint8_t cols = 16, uint8_t rows = 2);
Display(uint8_t addr = 0x27, uint8_t cols = 20, uint8_t rows = 4);
void begin();
void drawJoystick(double x, double y, bool pressed);
+3
View File
@@ -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;
};
+2 -2
View File
@@ -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)