Оформи код соответствующим тэгом, см. Правила
Вообщем идея такая:если кол не равен полученному, то зумер пищит одну секунду. Но почему-то зуммер пищит без остановки и на секунду прекращает, когда я ввожу неверный код:
#include <Keypad.h>
String f = "2121";
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1', '4', '7', '*'},
{'2', '5', '8', '0'},
{'3', '6', '9', '#'},
{'A', 'B', 'C', 'D'}
};
byte rowPins[ROWS] = {6, 5, 4, 3};
byte colPins[COLS] = {10, 9, 8, 7};
String s = "";
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup() {
pinMode(1, OUTPUT);
}
void loop() {
if (s.length() < 4) {
char customKey = customKeypad.getKey();
if (customKey) {
s += customKey;
}
} else {
if (s.length() == 4) {
if (s != f) {
digitalWrite(1, HIGH);
delay(1000);
digitalWrite(1, LOW);
s = "";
} else {
s = "";
}
} else {
s = "";
}
}
}
#include <Keypad.h>
String f = "2121";
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1', '4', '7', '*'},
{'2', '5', '8', '0'},
{'3', '6', '9', '#'},
{'A', 'B', 'C', 'D'}
};
byte rowPins[ROWS] = {6, 5, 4, 3};
byte colPins[COLS] = {10, 9, 8, 7};
String s = "";
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup() {
pinMode(1, OUTPUT);
}
void loop() {
if (s.length() < 4) {
char customKey = customKeypad.getKey();
if (customKey) {
s += customKey;
}
} else {
if (s.length() == 4) {
if (s != f) {
digitalWrite(1, HIGH);
delay(1000);
digitalWrite(1, LOW);
s = "";
} else {
s = "";
}
} else {
s = "";
}
}
}