//RANGGA AULIA RAHMAN
//20/456849/TK/50673
/*********************************************/
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {//mapping karakter
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {4, 5, 6, 7}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 9, 10, 11}; //connect to the column pinouts of the keypad
//Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
//LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
unsigned char debouncing (int i)
{
delay(10);
if(digitalRead(colPins[i])==LOW)
{
delay(10);
while (!(digitalRead(colPins[i]))){};
return i;
}
}
unsigned char cek_kolom(void)
{
for (int i = 0; i < 4; i++)
{
if (digitalRead(colPins[i])==LOW)
{
return debouncing(i);
}
}
return (4);
}
unsigned char _activate_row(unsigned char row_th)
{
unsigned char out_clm;
//DDRF|=0x0F;
//PORTF=0xFF;
for(char i=0;i<4;i++){
digitalWrite(rowPins[i], HIGH);
}
digitalWrite(rowPins[row_th],LOW);
out_clm=cek_kolom();
return out_clm;
}
unsigned char ReadKeypad(void)
{
unsigned char tmp, get_dt_loop,conter_tmb;
tmp=4;
for (conter_tmb=0;conter_tmb<4;conter_tmb++)
{
tmp=_activate_row(conter_tmb);
if(tmp<4)
return keys[conter_tmb][tmp];
}
if(conter_tmb==4) return 0;
}
void setup() {
// put your setup code here, to run once:
char i;
for(i=0;i<4;i++){
pinMode(rowPins[i], OUTPUT);
pinMode(colPins[i], INPUT_PULLUP);
}
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
unsigned char keypressed = ReadKeypad();
if (keypressed != 0)
{
Serial.println((char)keypressed);
}
}