#include <Arduino.h>
#include <U8x8lib.h> // u8x8 library for drawing on the OLED display
#define UP_BUTTON PB0
#define LEFT_BUTTON PB1
#define RIGHT_BUTTON PB2
#define DOWN_BUTTON PB5
U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/ 4, /* data=*/ 3, /* reset=*/ U8X8_PIN_NONE); // software IIC communication with the OLED display
void setup(void)
{
u8x8.begin(); // display initialization
u8x8.setPowerSave(0); // this is required
pinMode(UP_BUTTON, INPUT_PULLUP); // Configure button pins as input with pull-up resistor
pinMode(LEFT_BUTTON, INPUT_PULLUP);
pinMode(RIGHT_BUTTON, INPUT_PULLUP);
pinMode(DOWN_BUTTON, INPUT_PULLUP);
}
void loop(void)
{
u8x8.setFont(u8x8_font_chroma48medium8_r); // set some random font
if (digitalRead(UP_BUTTON) == LOW) { // If the up button is pressed
u8x8.clear(); // Clear the display
u8x8.drawString(0, 0, "Up"); // Print "Up" on the display
} else if (digitalRead(LEFT_BUTTON) == LOW) { // If the left button is pressed
u8x8.clear(); // Clear the display
u8x8.drawString(0, 0, "Left"); // Print "Left" on the display
} else if (digitalRead(RIGHT_BUTTON) == LOW) { // If the right button is pressed
u8x8.clear(); // Clear the display
u8x8.drawString(0, 0, "Right"); // Print "Right" on the display
} else if (digitalRead(DOWN_BUTTON) == LOW) { // If the down button is pressed
u8x8.clear(); // Clear the display
u8x8.drawString(0, 0, "Down"); // Print "Down" on the display
} else { // If no button is pressed
u8x8.clear(); // Clear the display
u8x8.drawString(0, 0, "No Button Pressed"); // Print "No Button Pressed" on the display
}
delay(200); // Adjust delay as needed
}