2016-12-14 42 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

您需要輸入設備才能輸入密碼。一個簡單的例子可以是10個開關,其中每個開關代表1,因此我們的密碼必須在0到10之間。您將開關值加在一起並與設定的密碼進行比較。其餘的對你來說應該很容易。

+0

他已經有了鍵盤和密碼檢查。 –

+0

哦,我沒看到。是的,他的代碼。好吧,他應該試試underts和代碼,如果它不是由他寫的。 –