#include <Keypad.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// Joystick pins rename
#define VERT_PIN 19
#define HORZ_PIN 18
// OLED
#define SCREEN_WIDTH 128 // OLED width, in pixels
#define SCREEN_HEIGHT 64 // OLED height, in pixels
// create an OLED display object connected to I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
const uint8_t ROWS = 4;
const uint8_t COLS = 3;
char keys[ROWS][COLS] = {
{ '1', '2', '3'},
{ '4', '5', '6'},
{ '7', '8', '9'},
{ 'A', '0', 'B'}
};
uint8_t colPins[COLS] = { 25, 33, 32 }; // Pins connected to C1, C2, C3
uint8_t rowPins[ROWS] = { 13, 14, 27, 26 }; // Pins connected to R1, R2, R3, R4
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(115200);
// Declare input for Joystick
pinMode(VERT_PIN, INPUT);
pinMode(HORZ_PIN, INPUT);
// initialize OLED display with I2C address 0x3C
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("failed to start SSD1306 OLED"));
while (1);
}
delay(2000); // wait two seconds for initializing
oled.clearDisplay(); // clear display
oled.setTextSize(1); // set text size
oled.setTextColor(WHITE); // set text color
oled.setCursor(0, 2); // set position to display (x,y)
// oled.println("Robotronix"); // set text
// oled.display(); // display on OLED
}
void loop() {
char key = keypad.getKey();
int vert = analogRead(VERT_PIN);
int horz = analogRead(HORZ_PIN);
// horz goes from 0 (right) to 1023 (left)
// vert goes from 0 (bottom) to 1023 (top)
if (key == A) {
Serial.println(key);
}
}