#include <Keypad.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
byte keys[ROWS][COLS] = {
  {9,1,10,5,},
  {3,16,4,6},
  {11,2,12,13},
  {7,8,14,15}
};
// pin uscita
byte rowPins[ROWS] = { 9, 8, 7, 6}; 
byte colPins[COLS] = { 5, 4, 3, 2}; 
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
  Serial.begin(9600);
Serial.println("setup");
    // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
   if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    
   }
  // // Show initial display buffer contents on the screen --
  // // the library initializes this with an Adafruit splash screen.
   display.clearDisplay();
   display.setTextSize(2);             // Normal 1:1 pixel scale
   display.setTextColor(SSD1306_WHITE);        // Draw white text
   display.setCursor(0,0);             // Start at top-left corner
   display.print("X ");
   display.display();
  delay(2000); // Pause for 2 seconds
   keypad.begin( makeKeymap(keys) );
    
    //keypad.addEventListener(keypadEvent_routine);  // Add an event listener.
    keypad.setHoldTime(300);                   // Default is 1000mS
    
}
void loop() {
  // put your main code here, to run repeatedly:
}