#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
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'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
#define DHTPIN 13
#define DHTTYPE DHT22
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
LiquidCrystal_I2C lcd(0x27, 16, 2);
DHT dht(DHTPIN, DHTTYPE);
int steps = 200;
byte directionPin = A2;
byte stepPin = A3;
int joy = A0;
int leftbtn = 11;
int rightbtn = 12;
int bottombtn = 10;
int topbtn = A1;
int joybtn = 1;
int centerbtn = 0;
String password = "3462";
String chpass = "";
bool passed = false;
bool Made = false;
bool key = false;
bool pos = false;
bool IDTMb = false;
bool ok = false;
int IDT = 23;
String M = "S";
String IDTM = "MAN";
int MS;
int Min = 1;
int Max = 10;
char currentMode;
long previous = 0;
void setup(){
Serial.begin(9600);
lcd.init();
lcd.backlight();
dht.begin();
Serial.println(analogRead(topbtn));
pinMode(directionPin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(leftbtn, INPUT_PULLUP);
pinMode(rightbtn, INPUT_PULLUP);
pinMode(topbtn, INPUT_PULLUP);
pinMode(bottombtn, INPUT_PULLUP);
pinMode(centerbtn, INPUT_PULLUP);
for(int i = 0; i <= 2; i++){
lcd.setCursor(5, 0);
lcd.print("Loading");
delay(300);
lcd.setCursor(5, 0);
lcd.print("Loading.");
delay(300);
lcd.setCursor(5, 0);
lcd.print("Loading..");
delay(300);
lcd.setCursor(5, 0);
lcd.print("Loading...");
delay(300);
lcd.setCursor(12, 0);
lcd.print(" ");
}
lcd.clear();
}
void loop() {
char keypad = customKeypad.getKey();
int temp = dht.readTemperature();
int joyvalue = analogRead(joy);
if(!passed){
lcd.setCursor(0, 0);
lcd.print("Password: ");
if(keypad){
chpass += keypad;
lcd.setCursor(10, 0);
lcd.print(chpass);
if(chpass.length() == 4){
if(password == chpass){
lcd.clear();
lcd.setCursor(5, 0);
lcd.print("Correct");
delay(500);
passed = true;
lcd.clear();
Made = true;
}
else{
lcd.clear();
lcd.setCursor(5, 0);
lcd.print("Wrong");
delay(500);
passed = false;
lcd.clear();
chpass = "";
}
}
}
}
if(passed && Made){
lcd.setCursor(2,0);
lcd.print("Made By Zeyd");
delay(2500);
Made = false;
lcd.clear();
}
if(passed && !Made && !key){
lcd.setCursor(0,0);
lcd.print("T");
lcd.setCursor(2,0);
lcd.print("IDT");
lcd.setCursor(7,0);
lcd.print("M");
lcd.setCursor(9,0);
lcd.print("IDTM");
lcd.setCursor(14,0);
lcd.print("MS");
lcd.setCursor(0,1);
lcd.print(temp);
lcd.setCursor(3,1);
lcd.print(IDT);
lcd.setCursor(7,1);
lcd.print(M);
lcd.setCursor(9,1);
lcd.print(IDTM);
lcd.print(" ");
lcd.setCursor(13,1);
lcd.print(MS);
}
if(passed && !Made){
if(keypad){
lcd.clear();
currentMode = keypad;
}
}
switch(currentMode){
case 'A':
key = true;
lcd.setCursor(0,0);
lcd.print("T");
lcd.setCursor(2,0);
lcd.print("IDT");
lcd.setCursor(7,0);
lcd.print("M");
lcd.setCursor(9,0);
lcd.print("IDTM");
lcd.setCursor(13,0);
lcd.print("MS");
lcd.setCursor(0,1);
lcd.print(temp);
lcd.setCursor(2,1);
lcd.print(IDT);
lcd.setCursor(7,1);
lcd.print(M);
lcd.setCursor(9,1);
lcd.print(IDTM);
lcd.print(" ");
lcd.setCursor(13,1);
lcd.print(MS);
break;
case 'B':
key = true;
lcd.setCursor(3, 0);
lcd.print("TEMP");
lcd.setCursor(11, 0);
lcd.print("IDT");
lcd.setCursor(3, 1);
lcd.print(temp);
lcd.setCursor(11, 1);
lcd.print(IDT);
chane('B');
break;
case 'C':
key = true;
lcd.setCursor(3,0);
lcd.print("Max");
lcd.setCursor(11,0);
lcd.print("Min");
lcd.setCursor(3,1);
lcd.print(Max);
lcd.print(" ");
lcd.setCursor(11,1);
lcd.print(Min);
lcd.print(" ");
chane('C');
}
if(digitalRead(centerbtn) == LOW && IDTMb == false){
IDTM = "AV";
IDTMb = true;
}
else if(digitalRead(centerbtn) == LOW && IDTMb == true){
IDTM = "MAN";
IDTMb = false;
}
if(IDTM == "MAN"){
MS = Max;
step();
}
else if(IDTM == "AV"){
chanejoy();
step();
}
}
void chane(char ned){
if(digitalRead(rightbtn) == LOW){
pos = true;
}
else if(digitalRead(leftbtn) == LOW){
pos = false;
}
if(ned == 'B'){
if(!pos){
lcd.setCursor(7, 0);
lcd.print("<");
delay(100);
lcd.setCursor(7, 0);
lcd.print(" ");
}
else{
lcd.setCursor(15, 0);
lcd.print("<");
delay(100);
lcd.setCursor(15, 0);
lcd.print(" ");
topb(IDT, 'A');
}
}
if(ned == 'C'){
if(!pos){
lcd.setCursor(7, 0);
lcd.print("<");
delay(100);
lcd.setCursor(7, 0);
lcd.print(" ");
topb(Max, 'B');
}
else{
lcd.setCursor(15, 0);
lcd.print("<");
delay(100);
lcd.setCursor(15, 0);
lcd.print(" ");
topb(Min, 'C');
}
}
}
void topb(int value, char kind){
if(digitalRead(topbtn) == LOW){
value += 1;
}
else if(digitalRead(bottombtn) == LOW){
value -= 1;
}
if(kind == 'A'){
IDT = value;
}
else if(kind == 'B'){
Max = value;
}
else if(kind == 'C'){
Min = value;
}
}
void chanejoy(){
int joyvalue = analogRead(joy);
if(joyvalue == 1023){
MS++;
Serial.println("WFT");
}
else if(joyvalue == 0){
MS--;
Serial.println("WTF");
}
if(MS > Max){
MS = Max;
}
else if(MS < Min){
MS = Min;
}
}
void step(){
Serial.println(MS);
long currentMillis = millis();
digitalWrite(directionPin, HIGH);
int stepstate = 200;
for(int i = 0; i < 200; i++){
if(currentMillis - 0 >= MS ){
previous = currentMillis;
if(stepstate = 200){
stepstate -= 200;
analogWrite(stepPin, stepstate);
}
if(stepstate == 0){
stepstate += 200;
analogWrite(stepPin, stepstate);
}
}
}
}