#include <Keypad.h>

const int ledPins[] = {6, 7, 8, 9};  // Define the pins for your LEDs
const int numRows = 4;
const int numCols = 4;

char keys[numRows][numCols] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

byte pin_rows[numRows] = {5, 4, 3, 2};   // Rows 0 to 3
byte pin_column[numCols] = {A3, A2, A1, A0};   // Columns 0 to 3

Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, numRows, numCols);

void setup() {
  for (int i = 0; i < 4; i++) {
    pinMode(ledPins[i], OUTPUT);  // Set LED pins as output
  }
}

void loop() {
  char key = keypad.getKey();

  if (key != NO_KEY) {
    int value = key - '0';  // Convert char to integer

    // Display binary representation on LEDs
    displayBinary(value);

    delay(1000);  // Adjust delay as needed
    resetLEDs();
  }
}

void displayBinary(int value) {
  for (int i = 0; i < 4; i++) {
    digitalWrite(ledPins[i], bitRead(value, i));  // Set LEDs based on binary representation
  }
}

void resetLEDs() {
  for (int i = 0; i < 4; i++) {
    digitalWrite(ledPins[i], LOW);
  }
}