
#include <Keypad.h> const byte ROWS = 4;const byte COLS = 3;char hexaKeys[ROWS][COLS] = {
{'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'}, {'*', '0', '#'}};int index = 0;char password[4] = {'1', '2', '3', '4'};char userPassword[4] = {};bool alarm = false;bool guardOn = false;byte rowPins[ROWS] = {11, 10, 9, 8};byte colPins[COLS] = {7, 6, 5};Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);bool checkPass() { for (int i = 0; i < sizeof(password); i++) { if (password[i] != userPassword[i]) { return false; } } return true;}void setup() { pinMode(2, OUTPUT); pinMode(3, INPUT); Serial.begin(9600);}void loop() { char customKey = customKeypad.getKey(); if (customKey) { if (customKey == '#') { guardOn = true; } else if (customKey == '*') { // Handle '*' key press if needed } else { userPassword[index] = customKey; index++; Serial.println(checkPass()); if (checkPass()) { alarm = false; guardOn = false; index = 0; for (int i = 0; i < sizeof(userPassword); i++) { userPassword[i] = '*'; } } } } if (guardOn) { digitalWrite(2, HIGH); if (digitalRead(3)) { tone(A0, 100); } } else { digitalWrite(2, LOW); noTone(A0); } сделайте чтоб код скидывался при нажатии на * на клавиатуре 4×4 в тинкеркад срочно нужно помогите умоляю 

Ответы на вопрос




To modify the code so that it resets when the "*" key is pressed on a 4x4 keypad in Tinkercad, you can make the following changes:
```cpp
#include
const byte ROWS = 4; const byte COLS = 4; char hexaKeys[ROWS][COLS] = { {'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', 'C'}, {'*', '0', '#', 'D'} }; int index = 0; char password[4] = {'1', '2', '3', '4'}; char userPassword[4] = {}; bool alarm = false; bool guardOn = false; byte rowPins[ROWS] = {11, 10, 9, 8}; byte colPins[COLS] = {7, 6, 5, 4}; Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
bool checkPass() { for (int i = 0; i < sizeof(password); i++) { if (password[i] != userPassword[i]) { return false; } } return true; }
void setup() { pinMode(2, OUTPUT); pinMode(3, INPUT); Serial.begin(9600); }
void loop() { char customKey = customKeypad.getKey(); if (customKey) { if (customKey == '#') { guardOn = true; } else if (customKey == '*') { // Reset the user password and index for (int i = 0; i < sizeof(userPassword); i++) { userPassword[i] = '\0'; } index = 0; } else { userPassword[index] = customKey; index++; Serial.println(checkPass()); if (checkPass()) { alarm = false; guardOn = false; index = 0; for (int i = 0; i < sizeof(userPassword); i++) { userPassword[i] = '*'; } } } }
if (guardOn) { digitalWrite(2, HIGH); if (digitalRead(3)) { tone(A0, 100); } } else { digitalWrite(2, LOW); noTone(A0); } } ```
In this modified code, the "*" key is detected in the `loop()` function using the `customKeypad.getKey()` function. If the "*" key is pressed, the user password and index are reset to their initial values. The user password is reset by setting each element of the `userPassword` array to `'\0'`, and the index is set to 0. This ensures that the password input starts from the beginning.
Please note that this modified code assumes that you are using a 4x4 keypad with the "*" key in the fourth column and fourth row. If your keypad layout is different, you may need to adjust the `hexaKeys` array accordingly.
I hope this helps! Let me know if you have any further questions.


Похожие вопросы

Топ вопросов за вчера в категории Информатика







Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili