diff --git a/README.md b/README.md index 8ad91bd..62eee4b 100644 --- a/README.md +++ b/README.md @@ -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 -- SSD1306 OLED Display (128x64) +- HD44780 Character LCD ## 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`. diff --git a/include/display.hpp b/include/display.hpp index 7409aa2..b6c8929 100644 --- a/include/display.hpp +++ b/include/display.hpp @@ -1,16 +1,16 @@ #pragma once #include -#include +#include /* - * A helper class to facilitate drawing on the SSD1306 OLED display using the U8g2 library. + * A helper class to facilitate drawing on a HD44780 LCD display. */ class Display { public: - Display(); + Display(uint8_t addr = 0x27, uint8_t cols = 16, uint8_t rows = 2); - bool begin(); + void begin(); void drawJoystick(double x, double y, bool pressed); private: - U8G2_SSD1306_128X64_NONAME_F_HW_I2C oled; + LiquidCrystal_I2C lcd; }; diff --git a/platformio.ini b/platformio.ini index ddfaf89..e52acec 100644 --- a/platformio.ini +++ b/platformio.ini @@ -19,4 +19,4 @@ monitor_speed = 9600 ; External libraries lib_deps = embeddedartistry/LibPrintf@1.2.13 - olikraus/U8g2@2.36.18 + marcoschwartz/LiquidCrystal_I2C@1.1.4 diff --git a/src/display.cpp b/src/display.cpp index a577cfa..2650344 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -1,34 +1,23 @@ #include "display.hpp" -// Initialize the OLED display with the appropriate settings for the SSD1306 128x64 display utilizing hardware I2C. -// The constructor initializes the U8g2 library with the correct parameters for the display and communication method. -Display::Display() : oled(U8G2_R0, U8X8_PIN_NONE) {} +// Initialize the LCD display with the specified number of columns and rows, using the I2C address. +Display::Display(uint8_t addr, uint8_t cols, uint8_t rows) : lcd(addr, cols, rows) {} -// Try to initialize the OLED display. If initialization fails, print an error message to the serial console and return false. -// Otherwise, set the default font and return true. -bool Display::begin() { - if (!oled.begin()) { - Serial.println("Failed to initialize OLED display"); - return false; - } - - oled.setFont(u8g2_font_profont22_mn); - return true; +void Display::begin() { + lcd.init(); } // TODO: Remove this method in the future void Display::drawJoystick(double x, double y, bool pressed) { - oled.clearBuffer(); + lcd.clear(); - // Map the joystick values from -100 to 100 to the display coordinates (0 to 128 for X and 0 to 64 for Y) - int16_t centerX = oled.getWidth() / 2; - int16_t centerY = oled.getHeight() / 2; - int16_t posX = map(x, -100, 100, centerX - 50, centerX + 50); - int16_t posY = map(y, -100, 100, centerY + 50, centerY - 50); // Invert Y-axis for display + lcd.setCursor(0, 0); + lcd.print("X:"); + lcd.print(x, 2); // Print X value with 2 decimal places + lcd.print(" Y:"); + lcd.print(y, 2); // Print Y value with 2 decimal places - // Draw the joystick position as a filled circle - oled.setDrawColor(1); // Set color to white - oled.drawCircle(posX, posY, pressed ? 10 : 5); // Larger circle if pressed - - oled.sendBuffer(); + lcd.setCursor(0, 1); + lcd.print("Pressed: "); + lcd.print(pressed ? "Yes" : "No"); } diff --git a/src/main.cpp b/src/main.cpp index caa221c..86c09a7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,13 +12,7 @@ void setup() { delay(10); } - // In case of OLED initialization failure, enter infinite loop - if (!display.begin()) { - while (true) { - delay(1000); - } - } - + display.begin(); pinMode(LED_BUILTIN, OUTPUT); }