You are on page 1of 3

Dari gambar tersebut wiring diagram.

Pin kolom 1 keypad terhubung dengan pin digital 5


Pin kolom 2 keypad terhubung dengan pin digital 6
Pin kolom 3 keypad terhubung dengan pin digital 7
Pin baris A keypad terhubung dengan pin digital 4
Pin baris B keypad terhubung dengan pin digital 3
Pin baris C keypad terhubung dengan pin digital 2
Pin baris D keypad terhubung dengan pin digital 1
Pin A decoder 7447 terhubung dengan pin digital 11
Pin B decoder 7447 terhubung dengan pin digital 10
Pin C decoder 7447 terhubung dengan pin digital 9
Pin D decoder 7447 terhubung dengan pin digital 8
//////////////////////////////////////////////////////
PORTB maps to Arduino digital pins 8 to 13 The two high bits (6 & 7) map to the
crystal pins and are not usable
DDRB - The Port B Data Direction Register - read/write
PORTB - The Port B Data Register - read/write
PINB - The Port B Input Pins Register - read only
Artinya ~> Misal B001111 berarti antara pin 13 - pin 8, yg dipakai hanya pin 11-
8 (urut sesuai binnernya dr kiri ke kanan)
/////////////////////////////////////////////////////////

/*
Program Akses Keypad dan Seven Segment Display
Arduino Uno
*/
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 3;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3'}, //baris A pin 4
{'4', '5', '6'}, //baris B pin 3
{'7', '8', '9'}, //baris C pin 2
{'*', '0', '#'} //baris D pin 1
};
byte rowPins[ROWS] = {4, 3, 2, 1};
byte colPins[COLS] = {5, 6, 7};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS)
;
int last;
void setup()
{
last = 0;
}
void loop()
{
DDRB = 15; //B001111 = 15
char customKey = customKeypad.getKey();
switch (customKey)
{
case '1':
PORTB = 8; //B001000
last = PORTB;
break;
case '2':
PORTB = 4; //B000100
last = PORTB;
break;
case '3':
PORTB = 12; //B001100
last = PORTB;
break;
case '4':
PORTB = 2; //B000010
last = PORTB;
break;
case '5':
PORTB = 10;
last = PORTB;
break;
case '6':
PORTB = 6;
last = PORTB;
break;
case '7':
PORTB = 14;
last = PORTB;
break;
case '8':
PORTB = 1;
last = PORTB;
break;
case '9':
PORTB = 9;
last = PORTB;
break;
case '0':
PORTB = 0;
last = PORTB;
break;
case '*':
PORTB = last;
break;
case '#':
PORTB = 15;
break;
}
}

You might also like