Arduino dvere
zdravim vie mi niekto poradit co treba prerobit aby mi to po dakom case znova zamklo. display po case zmeny ale ostatok nie dakujem
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Inicializa o display no endereco 0x27
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3, POSITIVE);
// letsarduino.com
// [Project 20] - Arduino Door Lock Using 4x4 Keypad and Servo Motor
#include <Keypad.h>
#include <Servo.h>
Servo servo_Motor;
char* password = "123";
int position = 0;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = { 8, 7, 6, 9 };
byte colPins[COLS] = { 5, 4, 3, 2 };
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int redPin = 12;
int greenPin = 13;
void setup()
{
lcd.begin (16,2);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
servo_Motor.attach(11);
setLocked(true);
}
void loop()
{
char key = keypad.getKey();
if (key == '*' || key == '#')
{
position = 0;
setLocked(true);
}
if (key == password[position])
{
position ++;
}
if (position == 3)
{
setLocked(false);
}
delay(100);
}
void setLocked(int locked)
{
if (locked)
{
lcd.setBacklight(HIGH);
lcd.setCursor(0,0);
lcd.print("PASSWORD !!");
lcd.setCursor(0,1);
lcd.print("ZATVORENE");
delay(1000);
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
servo_Motor.write(11);
}
else
{
lcd.setBacklight(HIGH);
lcd.setCursor(0,0);
lcd.print("KOD OK !!");
lcd.setCursor(0,1);
lcd.print("OTVORENE");
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
servo_Motor.write(90);
}
delay(1000);
return lcd.begin (16,2);
}
Vcelku trivoska ne?
Kdyz udelas setlock a zamknes, tak si jeste nastavis nejakou promenou na 10x pozadovanej cas do opetovnyho zamknuti. Tu pak budes v hlavnim cyklu dekrementovat a az bude nula, tak zase zamknes. Na display ,uzes vypisovat tuhle promenou/10 jako zbyvajici cas v sekundach, eventualne jeste odpocitat minuty.