#include <Servo.h>
#include <Keypad.h>
Servo myservo;
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
uint8_t colPins[COLS] = { 5, 4, 3, 2 };
uint8_t rowPins[ROWS] = { 9, 8, 7, 6 };
char disarmCode[4] = {'1','2','3','4'};
char tempArray[4];
String poradi[4] = {"prvni", "druhe", "treti", "ctvrte"};
int x = 4;
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void h ()
{
Serial.println("Zadej 4 místný kód ");
for (int i = 0; i <=3; i++)
{
Serial.println("Zadej " + poradi[i]);
char c;
do{
c = keypad.getKey();
}
while(c == NO_KEY);
tempArray[i] = c;
Serial.println(tempArray[i]);
}
}
bool compare() {
for(int i = 0; i < sizeof(disarmCode); i++)
{
if (tempArray[i] != disarmCode[i])
return false;
}
return true;
}
void setup() {
Serial.begin(9600);
myservo.attach(3);
myservo.write(90);
h();
if(compare())
{
myservo.write(0);
}
else
{
myservo.write(240);
}
}
void loop() {
}