2016-12-14 70 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和代码,如果它不是由他写的。 –