javaweb修改密码功能实现_「Arduino」利用4*4矩阵键盘来实现输入密码功能

该博客介绍了如何使用Arduino UNO和4*4矩阵键盘模拟javaweb的修改密码功能,通过EEPROM存储密码,并结合LED灯进行验证反馈。实验中详细列出了所需的材料和线路图,还提供了相应的代码实现。
摘要由CSDN通过智能技术生成
bbf60abadce53e52e0028301450cc55a.png

弄清楚类比于手机锁屏密码的模式,使用Arduino利用4*4矩阵键盘来实现输入密码功能,利用EEPROM实现保存密码功能。

本次完成的内容需要的材料:

Arduino UNO

一块4*4矩阵键盘

一个LED灯

导线(若干)

线路图:

9754363082885af32b1e3a9af12cd6af.png

实验所用的代码:

/* @file CustomKeypad.pde|| @version 1.0|| @author Alexander Brevig|| @contact alexanderbrevig@gmail.com|||| @description|| | Demonstrates changing the keypad size and key values.|| #*/#include "Keypad.h"#include const byte ROWS = 4; //four rowsconst byte COLS = 4; //four columns//define the cymbols on the buttons of the keypadschar hexaKeys[ROWS][COLS] = {  {'1','2','3','A'},  {'4','5','6','B'},  {'7','8','9','C'},  {'*','0','#','D'}};byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypadbyte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad//initialize an instance of class NewKeypadKeypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);int pass;void setup(){  Serial.begin(115200);  pinMode(13,OUTPUT);  pass = EEPROM.read(0);   Serial.println(pass);  delay(500);}void loop(){  char customKey = customKeypad.getKey();if (customKey){    Serial.println(customKey);    digitalWrite(13, LOW);  }  if(customKey == 'A')  {    int  a,b,c,d,q,i=0;        while(1)        {        char customKey = customKeypad.getKey();        if (customKey){    Serial.println(customKey);  }        if(i == 0&&customKey&&customKey!='#')        a = (int)(customKey)-48;        if(i == 1&&customKey)        {        b = (int)(customKey)-48;        }        if(i == 2&&customKey)        c = (int)(customKey)-48;        if(i == 3&&customKey){        d = (int)(customKey)-48;        }        if(customKey == '*')        a=b=c=d=q=i=0;        else if(customKey == '#')        {          q = a*1000+b*100+c*10+d;         EEPROM.write(0,q);         delay(100);          pass = EEPROM.read(0);          Serial.println(pass);         break;        }        if(customKey == '0'||customKey == '1'||customKey == '2'||customKey == '3'||customKey == '4'||customKey == '5'||customKey == '6'||customKey == '7'||customKey == '8'||customKey == '9')        {          i++;          if(i == 4)          {i = 0;}          }        }  }        if(customKey == 'B')  {      int  a,b,c,d,q,i=0;      char customKey = ' ';        while(1)        {        char customKey = customKeypad.getKey();        if (customKey){    Serial.println(customKey);  }        if(i == 0&&customKey&&customKey!='#')        a = (int)(customKey)-48;        if(i == 1&&customKey)        {        b = (int)(customKey)-48;        }        if(i == 2&&customKey)        c = (int)(customKey)-48;        if(i == 3&&customKey){        d = (int)(customKey)-48;        }        if(customKey == '0'||customKey == '1'||customKey == '2'||customKey == '3'||customKey == '4'||customKey == '5'||customKey == '6'||customKey == '7'||customKey == '8'||customKey == '9')        {          i++;          if(i == 4)          {i = 0;}          }        if(customKey == '*'){        a=b=c=d=q=i=0;        }        else if(customKey == '#')        {        Serial.println(a);        Serial.println(b);        Serial.println(c);         Serial.println(d);          q = a*1000+b*100+c*10+d;          if(q == pass)          {            Serial.println("sucess");             digitalWrite(13, HIGH);              break;          }          else          {            a=b=c=d=q=i=0;           }          }        }    }}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值