4.Listing Program [Kembali]
#include <Keypad.h> //memasukan pustaka keypad
char tombol[4][3] = //menyatakan tombol di keypad adalah kolom 3 dan baris 4
{ //pembuka tata letak keypad
{'1', '2', '3'}, //deklarasi posisi tombol keypad
{'4', '5', '6'}, //deklarasi posisi tombol keypad
{'7', '8', '9'}, //deklarasi posisi tombol keypad
{'*', '0', '#'} //deklarasi posisi tombol keypad
}; //penutup tata letak keypad
byte pin[] = {2, 3, 4, 5, 6, 7, 8, 9}; //deklarasi pin arduino pada seven segment dengan tipe data byte
byte pinBaris[] = {17, 18, 19, 20}; //deklarasi pin arduino yang dihubungkan ke baris pada keypad
byte pinKolom[] = {14, 15, 16}; //deklarasi pin arduino yang dihubungkan ke kolom pada keypad
Keypad keypad = Keypad(makeKeymap(tombol), //digunakan untuk menciptakan objek keypad
pinBaris, pinKolom, 4, 3); //objek keypad yaitu empat kali tiga
void setup() //fungsi utama
{
pinMode(10,OUTPUT); //pin 10 arduino digunakan sebagai output
digitalWrite(10,LOW); //pin 10 pada arduino digunakan pada keaadan low
}
void loop() //fungsi perulangan pada program
{
char kode = keypad.getKey(); //fungsi membaca tombol apa pada keypad yang ditekan
if (kode == NO_KEY) //keadaan jika tombol tidak ditekan
return; // perintah return dieksekusi
else if(kode == '0' || kode == '2' || kode == '4' || kode == '6' || kode == '8') //kondisi dimana tombol angka genap di tekan
{ for (int a=0; a<=5; a++){ //fungsi perulangan jika memenuhi syarat maka akan terus berulang
digitalWrite(2,HIGH); //pin 2 seven segment hidup
digitalWrite(3,LOW); //pin 3 seven segment mati
digitalWrite(4,LOW); //pin 4 seven segment mati
digitalWrite(5,HIGH); //pin 5 seven segment hidup
digitalWrite(6,HIGH); //pin 6 seven segment hidup
digitalWrite(7,HIGH); //pin 7 seven segment hidup
digitalWrite(8,HIGH); //pin 8 seven segment hidup
digitalWrite(9,LOW); //pin 9 seven segment mati
delay (100); //delay selama 100ms
digitalWrite(2,LOW); //pin 2 seven segment mati
digitalWrite(3,LOW); //pin 3 seven segment mati
digitalWrite(4,LOW); //pin 4 seven segment mati
digitalWrite(5,LOW); //pin 5 seven segment mati
digitalWrite(6,LOW); //pin 6 seven segment mati
digitalWrite(7,LOW); //pin 7 seven segment mati
digitalWrite(8,LOW); //pin 8 seven segment mati
digitalWrite(9,LOW); //pin 9 seven segment mati
delay (100); //delay selama 100ms
;
}
}
else if(kode == '1') //kondisi dimana angka satu ditekan
{digitalWrite(2,LOW); //pin 2 seven segment mati
digitalWrite(3,HIGH); //pin 3 seven segment hidup
digitalWrite(4,HIGH); //pin 4 seven segment hidup
digitalWrite(5,LOW); //pin 5 seven segment mati
digitalWrite(6,LOW); //pin 6 seven segment mati
digitalWrite(7,LOW); //pin 7 seven segment mati
digitalWrite(8,LOW); //pin 8 seven segment mati
digitalWrite(9,LOW); //pin 9 seven segment mati
}
else if(kode == '3') //kondisi dimana angka tiga ditekan
{ digitalWrite(2,HIGH); //pin 2 seven segment hidup
digitalWrite(3,HIGH); //pin 3 seven segment hidup
digitalWrite(4,HIGH); //pin 4 seven segment hidup
digitalWrite(5,HIGH); //pin 5 seven segment hidup
digitalWrite(6,LOW); //pin 6 seven segment mati
digitalWrite(7,LOW); //pin 7 seven segment mati
digitalWrite(8,HIGH); //pin 8 seven segment hidup
digitalWrite(9,LOW); //pin 9 seven segment mati
}
else if(kode == '5') //kondisi dimana angka lima ditekan
{ digitalWrite(2,HIGH); //pin 2 seven segment hidup
digitalWrite(3,LOW); //pin 3 seven segment mati
digitalWrite(4,HIGH); //pin 4 seven segment hidup
digitalWrite(5,HIGH); //pin 5 seven segment hidup
digitalWrite(6,LOW); //pin 6 seven segment mati
digitalWrite(7,HIGH); //pin 7 seven segment hidup
digitalWrite(8,HIGH); //pin 8 seven segment hidup
digitalWrite(9,LOW); //pin 9 seven segment mati
}
else if(kode == '7') //kondisi dimana angka tujuh ditekan
{ digitalWrite(2,HIGH); //pin 2 seven segment hidup
digitalWrite(3,HIGH); //pin 3 seven segment hidup
digitalWrite(4,HIGH); //pin 4 seven segment hidup
digitalWrite(5,LOW); //pin 5 seven segment mati
digitalWrite(6,LOW); //pin 6 seven segment mati
digitalWrite(7,LOW); //pin 7 seven segment mati
digitalWrite(8,LOW); //pin 8 seven segment mati
digitalWrite(9,LOW); //pin 9 seven segment mati
}
else if(kode == '9') //kondisi dimana angka sembilan ditekan
{ digitalWrite(2,HIGH); //pin 2 segment segment hidup
digitalWrite(3,HIGH); //pin 3 segment segment hidup
digitalWrite(4,HIGH); //pin 4 segment segment hidup
digitalWrite(5,HIGH); //pin 5 segment segment hidup
digitalWrite(6,LOW); //pin 6 segment segment mati
digitalWrite(7,HIGH); //pin 7 segment segment hidup
digitalWrite(8,HIGH); //pin 8 segment segment hidup
digitalWrite(9,LOW); //pin 9 segment segment mati
}
}