2016-12-14 11 views
-1

지금은 시스템을 작동시키고 PIR 센서 앞에서 손을 움직일 때 시스템이 어떻게 작동하는지 알려면 사용자로부터 비밀번호를 가져 오는 방법 시스템을 비활성화하십시오. 또한 시스템이 비활성 상태 일 때 화면에 "비활성"이라고 표시되어야합니다.알람이 울린 후 사용자 입력을 받아들이는 방법

#include <LiquidCrystal.h> 
#include <Password.h> 
#include <Keypad.h> 
//Password 
Password password = Password("1234"); 
LiquidCrystal lcd(0, 1, 10, 11, 12, 13); 

const byte ROWS = 4; 
const byte COLS = 4; 

char keys[ROWS][COLS] = { // Define the Keymap 
    { 
    '1','2','3','A'  } 
    , 
    { 
    '4','5','6','B'  } 
    , 
    { 
    '7','8','9','C'  } 
    , 
    { 
    '*','0','#','D'  } 
}; 

byte rowPins[ROWS] = {9,8,7,6}; 
byte colPins[COLS] = {5,4,3,2}; 
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS); 
int armed = 0; 
const int pir1 = A4; 
int sensorHit = 0; 
int alarmStatus = 0; 
int alarmActive = 0; 
int zone = 0; 

void setup() { 
    // put your setup code here, to run once: 
    lcd.begin(16,2); 
    pinMode(pir1, INPUT); 
    mainScreen(); 
    keypad.addEventListener(keypadEvent); 
} 

void loop() { 
    // put your main code here, to run repeatedly: 
    keypad.getKey(); 
    if(alarmActive == 1){ 
    if(digitalRead(pir1) == HIGH){ 
     zone = 0; 
     alarmTriggered(); 
    } 
    } 
} 
void keypadEvent(KeypadEvent eKey){ 
    switch (keypad.getState()){ 
    case PRESSED: 
    lcd.print(eKey); 
    switch (eKey){ 
    case '#': checkPassword(); break; 
    default: 
    password.append(eKey); 
    } 
    } 
} 
void alarmTriggered(){ 
    password.reset(); 
    alarmStatus = 1; 
    lcd.clear(); 
    lcd.setCursor(0,0); 
    lcd.print("SYSTEM TRIGGERED"); 
    lcd.print(0,1); 
    if(zone == 0){ 
    lcd.print(" FRONT DOOR OPEN "); 
    } 
} 
void checkPassword(){ 
    if (password.evaluate()){  //if code is correct: 
    lcd.clear();     //clear LCD 
    lcd.print("VALID PASSWORD"); //print message 
    password.reset();    //resets password after correct entry 
    delay(1500);     //wait... 
    lcd.clear();     //clear 
    if (alarmStatus==0 && alarmActive == 0){    //if system is off (ie: disarmed) 
     lcd.print("ARMED!");   //display message 
     alarmActive=1;      //system armed 
     alarmStatus=1; 
     delay(2000);     //wait 
     lcd.clear();     //clear 
     lcd.setCursor(0, 0);   //return to top left of LCD 
     lcd.print("Code to disarm:"); //back to where we began 
    } 
    else{ 
     lcd.print("DISARMED!");   //display message 
     alarmActive=0;      //system unarmed 
     alarmStatus=0; 
     delay(2000);     //wait 
     lcd.clear();     //clear 
     lcd.setCursor(0, 0);   //return to top left of LCD 
     lcd.print("Code to arm:");  //back to where we began 
    } 
    } 
    else{       //if password is incorrect: 
    lcd.clear(); 
    lcd.print("INVALID PASSWORD"); 
    password.reset();    //resets password after INCORRECT entry 
    delay(2000); 
    lcd.clear(); 
    lcd.setCursor(0, 0); 
    lcd.print("Retry Code:"); 
    } 
} 
void mainScreen(){ 
    lcd.clear(); 
    lcd.setCursor(0,0); 
    lcd.print("Enter Pin:"); 
} 
+0

정확히 무엇이 문제입니까? 코드가 어떻게 작동하지 않습니까? 우리는 코드 작성 서비스가 아닙니다. –

+0

또한 왜이 프로젝트에 대한 세 번째 계정이 질문입니까? –

답변

0

암호를 입력하려면 입력 장치가 필요합니다. 간단한 예가 각 스위치가 1을 나타내는 10 개의 스위치 일 수 있으므로 암호는 0에서 10 사이 여야합니다. 스위치 값을 함께 추가하고 설정된 암호와 비교하십시오. 나머지는 당신을 위해 쉬워야합니다.

+0

그는 이미 키패드와 암호 확인 기능을 가지고 있습니다. –

+0

오, 나는 그것을 보지 못했다. 그의 코드에서 옙. 그가 글을 쓰지 않았다면 그는 언더 코드와 코드를 시도해야한다. –