0% found this document useful (0 votes)
33 views3 pages

Algoritma Pemograman Jurnal

Uploaded by

Anzar Romadhon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views3 pages

Algoritma Pemograman Jurnal

Uploaded by

Anzar Romadhon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <Password.

h>
#include <Keypad.h>
#include <Servo.h>
Servo myservo;
int LEDmerah = 13;
int LEDhijau = 12;
Password password = Password( "6969" ); //Ubah password

const byte baris = 4; //Baris


const byte kolom = 4; //Kolom

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

byte barisPin[baris] = {9,8,7,6};


byte kolomPin[kolom]= {5,4,3,2};

// Buat objek keypad


Keypad keypad = Keypad( makeKeymap(keys), barisPin, kolomPin,
baris, kolom );

void setup(){
Serial.begin(9600);
delay(200);
pinMode(LEDhijau, OUTPUT); //Indikator Terbuka
pinMode(LEDmerah, OUTPUT); //Indikator Terkunci
myservo.attach(11); //Servo pada pin 11
keypad.addEventListener(keypadEvent);
}

void loop(){
keypad.getKey();
myservo.write(0);
}

void keypadEvent(KeypadEvent eKey){


switch (keypad.getState()){
case PRESSED:

Serial.print("Enter: ");
Serial.println(eKey);
delay(10);

Serial.write(254);

switch (eKey){
case 'A': Login(); delay(1); break;

case 'B': password.reset(); delay(1); break;

default: password.append(eKey); delay(1);


}
}
}

void Login(){
if (password.evaluate()){

Serial.println("Akses Diterima!");
Serial.write(254);
myservo.write(180);
digitalWrite(LEDhijau, HIGH);
delay(5000);
myservo.write(10);
digitalWrite(LEDhijau, LOW);
delay(500);
}

else{
Serial.println("Akses Ditolak!");
Serial.write(254);
delay(10);
myservo.write(0);
digitalWrite(LEDmerah, HIGH);
delay(500);
digitalWrite(LEDmerah, LOW);
}
}

You might also like