#include <Keypad.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <LiquidCrystal_I2C.h>
#include <Firebase_ESP_Client.h>
#define I2C_ADDR 0x27
#define Lcd_columns 16
#define Lcd_lines 4
#define FIREBASE_HOST "https://denemedurus-default-rtdb.firebaseio.com/"
#define FIREBASE_AUTH ""
uint8_t state = 0;
unsigned long ClockTimer;
unsigned long weatherAPItimer;
unsigned long weatherDisplayTimer;
uint8_t valIndex;
uint8_t cursorPos;
bool setTimeFromAPI();
const byte akim = 14;
const String endpoint = "http://worldtimeapi.org/api/timezone/Europe/Berlin";
struct timeval currentTime;
struct timeval stopTime;
struct timeval startTime;
int akimdeger();
const char* password = "";
const char* wid = "Wokwi-GUEST";
char entered_value [6];
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] = { 21, 20, 19, 18 };
uint8_t rowPins[ROWS] = { 35, 34, 33, 26 };
LiquidCrystal_I2C lcd(I2C_ADDR, Lcd_columns, Lcd_lines);
FirebaseData firebasedata;
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
bool setTimeFromAPI()
{
if ((WiFi.status() == WL_CONNECTED))
{
HTTPClient http;
http.begin(endpoint);
int httpCode = http.GET();
if (httpCode > 0)
{
String result = http.getString();
DynamicJsonDocument doc(2048);
DeserializationError error = deserializeJson(doc, result);
if (!error)
{
String timeStr = doc["datetime"].as<String>();
uint8_t i = timeStr.indexOf('T');
timeStr = timeStr.substring(i + 1, i + 9);
timeStr.replace(":", "");
char buf [6];
timeStr.toCharArray(buf, 6);
setTime(buf);
return true;
}
}
http.end();
}
return false;
}
void setTime(char time [6])
{
char hoursEntered [2] = { time[0],time[1] };
char minuteEntered [2] = { time[2], time[3] };
char secondsEntered [2] = { time[4],time[5] };
uint8_t hours = atoi(hoursEntered);
uint8_t minutes = atoi(minuteEntered);
uint32_t seconds = atoi(secondsEntered);
uint32_t hoursToMinutes = hours * 60;
uint32_t totalMinutes = hoursToMinutes + minutes;
seconds += totalMinutes * 60;
currentTime.tv_sec = seconds;
currentTime.tv_usec = 0 ;
settimeofday(¤tTime , NULL);
lcd.clear();
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Merhaba Hosgeldiniz");
Wire.begin(16,15);
lcd.init();
lcd.backlight();
WiFi.begin(wid,password);
while (WiFi.status() != WL_CONNECTED)
{
lcd.print(".");
delay(1000);
}
lcd.clear();
if(!setTimeFromAPI())
{
char t [] = __TIME__;
char compileTime [] = { t[0], t[1], t[3], t[4], t[6], t[7] };
setTime(compileTime);
}
Firebase.begin(FIREBASE_HOST,FIREBASE_AUTH );
Firebase.reconnectWiFi(true);
gettimeofday(¤tTime, NULL);
stopTime.tv_sec = currentTime.tv_sec;
pinMode(akim, INPUT);
}
void veri_yaz(String DurusTuru,String DurusSebebi)
{
gettimeofday(¤tTime,NULL);
int Dakika = curretTime.tv_sec / 60
Firebase.setFloat(firebasedata,"DurusTuru",0,"DurusSebebi",0,"Saniye",saniye)
}
int akimdeger()
{
int oku = analogRead(akim);
Serial.println(oku);
return oku;
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
if (akimdeger() >= 1065)
{
gettimeofday(¤tTime, NULL);
startTime.tv_sec = currentTime.tv_sec;
if (startTime.tv_sec - stopTime.tv_sec >= 5)
if (state == 0)
{
screen1();
veri_yaz("1","1");
}
getinput();
}
else
{
state = 0;
veri_yaz("1","1");
}
}
void screen1()
{
lcd.setCursor(0,0);
lcd.print("Durus Turu sec");
lcd.setCursor(0,1);
lcd.print("A plansiz");
lcd.setCursor(0,2);
lcd.print("B planli");
state = 1;
}
void recordScreen()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Bilgilendirme !!");
lcd.setCursor(0,1);
lcd.print("# durus kaydi");
lcd.setCursor(0,2);
lcd.print("* silme işlemi");
delay(3000);
lcd.clear();
}
void recordScreen1(String mesaj)
{
lcd.setCursor(0,0);
lcd.print(mesaj);
}
void getinput()
{
switch (state)
{
case 1:
Keyenter1();
break;
case 2:
Keyenter2();
break;
case 3:
Keyenter2();
break;
}
}
void Keyenter1() // bu veri giriş durumu planlı veya plansız girişlerin seçilmesi için kullanılıyor
{
char key = keypad.getKey();
switch(key)
{
case 'A':
state = 2;
recordScreen();
recordScreen1("Planlı Durus");
break;
case 'B':
state = 3;
recordScreen();
recordScreen1("Plansız Durus");
break;
case '#':
//rtc.silence();
break;
case '*':
//rtc.addToSnooze();
break;
}
}
void Keyenter2() // bu veri giriş durumu planlı veya plansız girişlerin kayıt edilmesi için kullanılıyor
{
char key = keypad.getKey();
switch(key)
{
case '#':
//kayit prosedürü burada
//state = 0;
break;
case '*':
eraseChar();
break;
default:
if (isDigit(key))
{
nextChar(key);
}
break;
}
}
void nextChar(char key)
{
if (valIndex < 6)
{
entered_value[valIndex] = key;
lcd.setCursor(0, 1);
lcd.print(entered_value);
cursorPos++;
valIndex++;
}
}
void eraseChar()
{
if (valIndex > 0 )
{
valIndex--;
cursorPos--;
entered_value[valIndex] = '\0';
lcd.setCursor(cursorPos, 1);
lcd.print(' ');
lcd.setCursor(cursorPos, 1);
}
}Loading
esp32-s2-devkitm-1
esp32-s2-devkitm-1