#include <SoftwareSerial.h>
#include <Keypad.h>

SoftwareSerial mySerial(12, 13);

const byte ROWS = 4; //four rows
const byte COLS = 3; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {1, 2, 3},
  {4, 5, 6},
  {7, 8, 9},
  {10, 12, 11}
};
const char yazilar[12][8] = {
  {0x00, 0x3c, 0x62, 0x52, 0x4a, 0x46, 0x3c, 0x00},//0
  {0x00, 0x00, 0x00, 0x22, 0x7E, 0x02, 0x00, 0x00}, //1
  {0x00, 0x00, 0x46, 0x8A, 0x92, 0x62, 0x00, 0x00},//2
  {0x00, 0x00, 0x44, 0x92, 0x92, 0x6C, 0x00, 0x00},//3
  {0x00, 0x00, 0x70, 0x10, 0x10, 0x7e, 0x00, 0x00},//4
  {0x00, 0x00, 0x72, 0x52, 0x52, 0x5e, 0x00, 0x00},//5
  {0x00, 0x00, 0x7e, 0x52, 0x52, 0x5e, 0x00, 0x00},//6
  {0x00, 0x00, 0x40, 0x4e, 0x50, 0x70, 0x00, 0x00},//7
  {0x00, 0x00, 0x2c, 0x52, 0x52, 0x2c, 0x00, 0x00},//8
  {0x00, 0x00, 0x70, 0x52, 0x52, 0x7e, 0x00, 0x00},//9
  {0x00, 0x00, 0x54, 0x38, 0x7c, 0x38, 0x54, 0x00},//*
  {0x00, 0x00, 0x24, 0x7e, 0x24, 0x7e, 0x24, 0x00}//#
};

byte rowPins[ROWS] = {A3, A4, A5, 11};//connect to the row pinouts of the keypad
byte colPins[COLS] = {A0, A1, A2}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup() {
  mySerial.begin(9600);
  for (int i = 0; i < 11; i++) {
    pinMode(i, OUTPUT);
  }
}

char ledEkran;
void loop() {
  char customKey = customKeypad.getKey();

  if (customKey) {
    mySerial.println(customKey);
    ledEkran = customKey;
  }

  for (int i = 0; i < 8; i++) {
    PORTB = (PORTB & 0xF8) | (0x07 & i);
    PORTD = yazilar[ledEkran % 12][i];
    delay(1);
    PORTD = 0x00;
  }
}
