Вопрос задан 25.10.2023 в 19:46. Предмет Информатика. Спрашивает Осипов Вадим.

#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 в тинкеркад срочно нужно помогите умоляю ​
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Будаева Адиса.
Попробуй метку сделать больше
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

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.

0 0

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

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

Последние заданные вопросы в категории Информатика

Задать вопрос