【发布时间】:2017-03-15 08:26:35
【问题描述】:
我正在做一个项目,我正在使用键盘输入密码,我所做的是我正在读取用户输入的密钥并将其收集到一个数组中以将其与密码。我面临的问题是,当我比较输入的单词和正确的密码时,我总是得到“错误密码”。
这是我的代码:
#include "Keypad.h"
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
char passwrd[7];
char cst[7]="*1998#";
byte rowPins[ROWS] = {28, 27, 26, 25}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {24, 23, 22}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup()
{
Serial.begin(9600);
}
void loop()
{
int i=0;
do
{
char key = keypad.getKey();
if (key != NO_KEY)
{
passwrd[i]=key;
i++;
Serial.println(key);
}
}while (i!=6);
Serial.println(passwrd);
Serial.println(cst);
if (passwrd==cst)
{
Serial.println("correct passwrd");
}
else
{
Serial.println("wrong passwrd");
}
}
这是我从串行 com 获得的信息:
*
1
9
9
8
#
*1998#
*1998#
wrong passwrd
问题出在哪里?
【问题讨论】: