WORK2.大师的秘密
TIME:2020/10/22
BACKGROUND.
上周出现的智者大师是快乐星球的精神领袖,球民们都十分敬仰他。
Master wise, who appeared last week, is the spiritual leader of happy planet, and the people of the world admire him very much.
但是,智者大师好像有他自己的秘密……
However, Mater wise seems to have his own secret ……
THOUGHTS.
智者大师似乎其实是个反派,因为他自己也打不开愿望之盒,所以他想要改造它,让所有人都打不开愿望之盒。
Master Sophie seems to be actually a villain, because he can't open the box of wishes, so he wants to transform it so that everyone can't open the box of wishes.
他将盒子进行了改造,在盒子上加了密码锁,如果输入密码错误累计三次的话,盒子在三十秒后就会爆炸!
He transformed the box and added a password lock to the box. If you input the wrong password three times, the box will explode in 30 seconds!
ARDUINO CODE.
#include <LiquidCrystal.h>//1602库
#include <Keypad.h>//键盘库
#include <EEPROM.h>//EEPROM库用来保存修改过的密码,掉电后不遗失
const byte ROWS = 4; //4行
const byte COLS = 4; //4列
//键盘位置
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {A0,A1,A2,A3}; //定义接键盘横排引脚
byte colPins[COLS] = {A4,A5,3,2}; //竖排引脚定义
//新的键盘对象
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
// 1602引脚,接法参照最上方注释
LiquidCrystal lcd(9,8,7,6,5,4);//lcd连接引脚
String oldPassword = "";//保存老密码
String newPassword = "";//保存输入的修改密码
int addNum = 0;//错误计数
String inPut = "";//保存输入字符串
String n = "";//字符串转整型用的变量
unsigned long now;//现在时间用于计时
unsigned long before;//参考时间用于计时
unsigned long delayTime = 30000;//锁定时间
void setup() {
Serial.begin(9600);//初始化串口
// 定义LCD两行16列
lcd.begin(16, 2);
//开机从EEPROM中读取密码,四位密码保存在EEPROM0-3地址当中
for (int i = 0; i < 4; i++)
{
oldPassword += EEPROM.read(i);
}
//串口打印测试信息
Serial.print("Old Password is : ");
Serial.println(oldPassword);
delay(2000);
lcd.setCursor(0, 0);//1602输出位置,格式列、行
lcd.print("Please input :");//1602输出
}
int i = 6;//'*'号开始位置
void loop() {
char customKey = customKeypad.getKey();//获取按键
if (customKey)//有按键按下
{
inPut += customKey;//保存输入
lcd.setCursor(i, 1);//在指定位置输出*号
lcd.print('*');
//串口打印测试信息
Serial.println("inPut is : ");
Serial.println(inPut);
Serial.println("onece");
i++;//后移1602输出*号位置
if (i > 9)//超过输出位置回归
{
i = 6;
}
}
//比较密码
if (inPut == oldPassword) //密码正确
{
addNum = 0;//错误次数清零
Serial.println("Bingo!");//串口打印测试信息
lcd.clear();//清屏
lcd.setCursor(4, 0);//输出位置
lcd.print("Bingo!");//输出bingo
delay(2000);//延时2秒
lcd.clear();//清屏
delay(500);
lcd.setCursor(0, 0); //1列1行
lcd.print("Change Password?");//lcd输出是否修改密码
Serial.println("change password?");//串口打印测试信息
lcd.setCursor(0, 1);
lcd.print("1.YES 2.NO");//lcd输出1yes2no
int a = 1;
while (a)//等待按键按下
{
customK
implementation technology.
ARDUINO.
VIDEO.
Please enjoy it!
Behind the scenes.
Production process display.
1/ PHOTOS
2/ VIDEOS