#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
int ledPins[] = {23,25,27,29,31,33,35,37}; //An array to hold the pin each LED is connect
long input;
const int ROW_NUM = 4; // four rows
const int COLUMN_NUM = 4; // four columns
char keys[ROW_NUM][COLUMN_NUM] = {
{'1','2','3', 'A'},
{'4','5','6', 'B'},
{'7','8','9', 'C'},
{'*','0','#', 'D'}
};
byte pin_rows[ROW_NUM] = {13, 12, 11, 10}; // connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {9, 8, 7, 6}; // connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
int cursorColumn = 0 <256;
void setup(){
Serial.begin(9600);
//for LED
for(int i = 0; i < 8; i++){ //this is a loop and will repeat eight times
pinMode(ledPins[i],OUTPUT); //we use this to set each LED pin to output
}
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.print("INPUT THE NUMBER");
delay(1000);
lcd.clear();
}
void loop(){
char key = keypad.getKey();
lcd.setCursor(0, 0);
lcd.print("BINER FROM");
if (key) {
lcd.setCursor(cursorColumn, 1); // move cursor to (cursorColumn, 0)
lcd.print(key); // print key at (cursorColumn, 0)
cursorColumn++; // move cursor to next position
if(cursorColumn == 2 || cursorColumn > 256) { // if reaching limit, clear LCD
lcd.clear();
cursorColumn = 0;
}
input=key-48;
Serial.println(input);
for (int i=(input); i<256; i++) {
outputbiner(input);
//delay(256-i);
//delay(2000);
return 0;
}
}
}
void outputbiner(int input) {
for (int i=0; i<8; i++) {
if (input%2)
digitalWrite(ledPins[i], HIGH);
else
digitalWrite(ledPins[i], LOW);
input/=2;
}
}