
Bu masa saati uygulamamızda OLED ekranı Adafruit kütüphanesi ile kullandık. Bu kütüphane ile bir çok çizimi yapabiliyoruz ve yazı büyüklüğünü ayarlayabiliyoruz. Deneyap sıcaklık ve nem modülünü kullanmadık. Kendi IMU sıcaklık modülü ile sıcaklığı ölçüp ekrana yazdırdık.
Masa saatinin özelliklerini şöyle sıralayabiliriz:
- Deneyap Dokunmatik tuş takımı ile zaman bilgisini girip ayar yapabiliyorsunuz. Burada dokunmatik tuş modülünün pinlerine en ufak bir temas olmaması gerekiyor. Çok hassas, hemen farklı rakamlara basılmış gibi oluyor. Hatta mini breadboard’a takıyorum, orada bile düzgün çalışmıyor. Bu nedenle hiç bir yere takmadan kullandım.
gün, ay, yıl, saat, dakika ve saniye bilgisini rakamlara basarak yazmayı tamamladığınızda ayarlamayı yapıyor. Ayar moduna geçmek için 1’e basmak gerekiyor. Ayarlamayı iptal etmek için herhangi bir zaman bilgisini 99 girmek yeterli oluyor. - Serial port kullanarak zaman bilgisini gg/aa/yyyy ss/dd/sn şeklinde yazıp gönderince saati zamanı ayarlıyor. Ancak önce zaman ayar moduna geçmek gerekiyor. Bunun içinde önce “Zaman Ayarla” yazıp gönderiyorsunuz.
- Seri işlemlerdeki sistemin aynısını bluetooth üzerinden de yapabilirsiniz. Bağlandığınız cihaza bluetooth üzerinden Zaman Ayarla yazısı gönderince modunu değiştiriyor. Doğru formatta tarih bilgisini girince de ayarlamayı yapıyor. Bu moddan çıkmak için “iptal” yazıp göndermek yeterli.
Bu uygulamamızda yazıları aynı bir liste veya dizi gibi kullandık ve bu anlamda bir örnek teşkil etmiş oldu. Ayrıca String ve int ifadeleri bir birine dönüştürdük. Bu da güzel bir örnek olmuş oldu.
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO: A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO: 2(SDA), 3(SCL), ...
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3D ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#include "lsm6dsm.h" // Dahili IMU kütüphanesi
// IMU (İvmeölçer) sensörünü başlatmak için bir LSM6DSM class'ı tanımlandı.
LSM6DSM IMU;
int sicaklik_degeri = 0.0;
#include <Deneyap_GercekZamanliSaat.h>
RTC GercekZamanliSaat;
DateTime now;
DateTime zamanAyarlama;
int zmnAyrImlec = 0;
String zmnAyarMetni = "__/__/____ __:__:__";
int ayrDay = 0;
int ayrMonth = 0;
long ayrYear = 0;
int ayrHour = 0;
int ayrMinute = 0;
int ayrSecond = 0;
String tempStr = "";
long tempInt = 0;
#include <Deneyap_DokunmatikTusTakimi.h>
Keypad Keypad;
int keyword;
#include "BluetoothSerial.h"
BluetoothSerial SerialBT;
String gelenYazi = "";
unsigned long timer1 = 0; //Zaman kesmesi gibi(!)
int mod = 0;
void MesajOLED(String mesaj = "Mesaj", int size = 1, int x = 0, int y = 0, int zaman = 1000, bool silinsinmi = true) {
display.clearDisplay();
display.setCursor(x, y);
display.setTextSize(size);
display.setTextColor(SSD1306_WHITE);
display.print(mesaj);
display.display();
delay(zaman);
if (silinsinmi) {
display.clearDisplay();
display.display();
}
}
void MesajHazirla(String mesaj = "Mesaj", int size = 1, int x = 0, int y = 0, bool gosterilsinmi = false) {
display.setCursor(x, y);
display.setTextSize(size);
display.setTextColor(SSD1306_WHITE);
display.print(mesaj);
if (gosterilsinmi) {
display.display();
}
}
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("- - - - - - - - - - - - - - - -");
delay(1000);
SerialBT.begin("DeneyapKart_01");
Serial.println("DeneyapKart_01 - Yayın başladı.");
Serial.println("- - - - - - - - - - - - - - - -");
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;)
; // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
//display.display();
//delay(2000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
display.display();
IMU.begin(); // IMU sensörümüzü başlatıldı.
delay(100);
//Gerçek Zamanlı Saat Modülü
if (!GercekZamanliSaat.begin()) {
delay(3000);
//Serial.println("I2C bağlantısı başarısız ");
while (1)
;
}
now = GercekZamanliSaat.now();
if (now.year() < 2025) {
GercekZamanliSaat.adjust(DateTime(2025, 6, 12, 20, 40, 0)); // yıl, ay, gün, saat, dakika, saniyeni ayarlanması
}
Keypad.begin(0x0E);
//pinMode(GPKEY, INPUT);
}
void loop() {
if (SerialBT.available()) {
gelenYazi = SerialBT.readString();
Serial.print("Gelen Yazı: ");
Serial.print(gelenYazi);
SerialBT.print(gelenYazi);
String tempYazi = gelenYazi.substring(0, gelenYazi.length() - 2);
MesajOLED(tempYazi, 1, 0, 0, 2000);
if (tempYazi == "Zaman Ayarla") {
if (mod != 1) {
mod = 1;
}
} else if (tempYazi == "iptal" || tempYazi == "iptal" || tempYazi == "İPTAL") {
mod = 0;
} else if (mod == 1) {
MetindenTariheAyarla(tempYazi);
}
gelenYazi = "";
}
if (Serial.available()) {
gelenYazi = Serial.readString();
Serial.print("Gelen Yazı: ");
Serial.print(gelenYazi);
String tempYazi = gelenYazi.substring(0, gelenYazi.length() - 1);
MesajOLED(tempYazi, 1, 0, 0, 2000);
if (tempYazi == "Zaman Ayarla") {
if (mod != 1) {
mod = 1;
}
} else if (tempYazi == "iptal" || tempYazi == "iptal" || tempYazi == "İPTAL") {
mod = 0;
} else if (mod == 1) {
MetindenTariheAyarla(tempYazi);
}
gelenYazi = "";
}
// if (!digitalRead(D8)) {
// zmnAyrImlec = 0;
// mod = 0;
// zmnAyarMetni = "__/__/____ __:__:__";
// }
switch (mod) {
case 0:
Timer();
keyword = Keypad.KeypadRead();
if (keyword != 0xFF) {
switch (keyword) {
case 0:
break;
case 1:
mod = 1;
zamanAyarlama = now;
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
}
}
break;
case 1:
ZamanAyariEkrani();
if (zmnAyrImlec == 2) {
tempStr = "";
tempStr += zmnAyarMetni[0];
tempStr += zmnAyarMetni[1];
tempInt = tempStr.toInt();
if ((tempInt < 1) || (31 < tempInt)) {
zmnAyarMetni[0] = '_';
zmnAyarMetni[1] = '_';
zmnAyrImlec = 0;
if (tempInt == 99) {
mod = 0;
zmnAyarMetni = "__/__/____ __:__:__";
zmnAyrImlec = 0;
}
} else {
ayrDay = tempInt;
zmnAyrImlec++;
}
} else if (zmnAyrImlec == 5) {
tempStr = "";
tempStr += zmnAyarMetni[3];
tempStr += zmnAyarMetni[4];
tempInt = tempStr.toInt();
if ((tempInt < 1) || (12 < tempInt)) {
zmnAyarMetni[3] = '_';
zmnAyarMetni[4] = '_';
zmnAyrImlec = 3;
if (tempInt == 99) {
mod = 0;
zmnAyarMetni = "__/__/____ __:__:__";
zmnAyrImlec = 0;
}
} else {
ayrMonth = tempInt;
zmnAyrImlec++;
}
} else if (zmnAyrImlec == 10) {
tempStr = "";
tempStr += zmnAyarMetni[6];
tempStr += zmnAyarMetni[7];
tempStr += zmnAyarMetni[8];
tempStr += zmnAyarMetni[9];
tempInt = tempStr.toInt();
if (tempInt < 2025) {
zmnAyarMetni[6] = '_';
zmnAyarMetni[7] = '_';
zmnAyarMetni[8] = '_';
zmnAyarMetni[9] = '_';
zmnAyrImlec = 6;
if (tempInt == 9999) {
mod = 0;
zmnAyarMetni = "__/__/____ __:__:__";
zmnAyrImlec = 0;
}
} else {
ayrYear = tempInt;
zmnAyrImlec++;
}
} else if (zmnAyrImlec == 13) {
tempStr = "";
tempStr += zmnAyarMetni[11];
tempStr += zmnAyarMetni[12];
tempInt = tempStr.toInt();
if ((tempInt < 0) || (23 < tempInt)) {
zmnAyarMetni[11] = '_';
zmnAyarMetni[12] = '_';
zmnAyrImlec = 11;
if (tempInt == 99) {
mod = 0;
zmnAyarMetni = "__/__/____ __:__:__";
zmnAyrImlec = 0;
}
} else {
ayrHour = tempInt;
zmnAyrImlec++;
}
} else if (zmnAyrImlec == 16) {
tempStr = "";
tempStr += zmnAyarMetni[14];
tempStr += zmnAyarMetni[15];
tempInt = tempStr.toInt();
if ((tempInt < 0) || (59 < tempInt)) {
zmnAyarMetni[14] = '_';
zmnAyarMetni[15] = '_';
zmnAyrImlec = 14;
if (tempInt == 99) {
mod = 0;
zmnAyarMetni = "__/__/____ __:__:__";
zmnAyrImlec = 0;
}
} else {
ayrMinute = tempInt;
zmnAyrImlec++;
}
} else if (zmnAyrImlec == 19) {
tempStr = "";
tempStr += zmnAyarMetni[17];
tempStr += zmnAyarMetni[18];
tempInt = tempStr.toInt();
if ((tempInt < 0) || (59 < tempInt)) {
zmnAyarMetni[17] = '_';
zmnAyarMetni[18] = '_';
zmnAyrImlec = 17;
if (tempInt == 99) {
mod = 0;
zmnAyarMetni = "__/__/____ __:__:__";
zmnAyrImlec = 0;
}
} else {
ayrSecond = tempInt;
GercekZamanliSaat.adjust(DateTime(ayrYear, ayrMonth, ayrDay, ayrHour, ayrMinute, ayrSecond)); // yıl, ay, gün, saat, dakika, saniyeni ayarlanması
zmnAyrImlec = 0;
mod = 0;
zmnAyarMetni = "__/__/____ __:__:__";
zmnAyrImlec = 0;
}
}
keyword = Keypad.KeypadRead();
if (keyword != 0xFF) {
switch (keyword) {
case 0:
zmnAyarMetni[zmnAyrImlec] = '0';
zmnAyrImlec++;
break;
case 1:
zmnAyarMetni[zmnAyrImlec] = '1';
zmnAyrImlec++;
break;
case 2:
zmnAyarMetni[zmnAyrImlec] = '2';
zmnAyrImlec++;
break;
case 3:
zmnAyarMetni[zmnAyrImlec] = '3';
zmnAyrImlec++;
break;
case 4:
zmnAyarMetni[zmnAyrImlec] = '4';
zmnAyrImlec++;
break;
case 5:
zmnAyarMetni[zmnAyrImlec] = '5';
zmnAyrImlec++;
break;
case 6:
zmnAyarMetni[zmnAyrImlec] = '6';
zmnAyrImlec++;
break;
case 7:
zmnAyarMetni[zmnAyrImlec] = '7';
zmnAyrImlec++;
break;
case 8:
zmnAyarMetni[zmnAyrImlec] = '8';
zmnAyrImlec++;
break;
case 9:
zmnAyarMetni[zmnAyrImlec] = '9';
zmnAyrImlec++;
break;
}
}
break;
case 2:
keyword = Keypad.KeypadRead();
if (keyword != 0xFF) {
switch (keyword) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
}
}
break;
case 3:
keyword = Keypad.KeypadRead();
if (keyword != 0xFF) {
switch (keyword) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
}
}
break;
case 4:
keyword = Keypad.KeypadRead();
if (keyword != 0xFF) {
switch (keyword) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
}
}
break;
case 5:
keyword = Keypad.KeypadRead();
if (keyword != 0xFF) {
switch (keyword) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
}
}
break;
}
}
void Timer() {
if (millis() - timer1 >= 1000 || millis() < timer1) {
timer1 = millis();
now = GercekZamanliSaat.now();
sicaklik_degeri = round(IMU.readTempC());
display.clearDisplay();
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0, 0);
display.print(sicaklik_degeri);
display.print(" C");
display.drawCircle(30, 4, 3, SSD1306_WHITE);
display.drawCircle(30, 4, 4, SSD1306_WHITE);
display.setCursor(0, 22);
if (now.day() < 10) {
display.print("0");
}
display.print(now.day());
display.print("/");
if (now.month() < 10) {
display.print("0");
}
display.print(now.month());
display.print("/");
display.print(now.year());
display.setCursor(0, 44);
if (now.hour() < 10) {
display.print("0");
}
display.print(now.hour());
display.print(":");
if (now.minute() < 10) {
display.print("0");
}
display.print(now.minute());
display.print(":");
if (now.second() < 10) {
display.print("0");
}
display.print(now.second());
display.display();
}
}
void ZamanAyariEkrani() {
display.clearDisplay();
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(8, 5);
if (zamanAyarlama.day() < 10) {
display.print("0");
}
display.print(zamanAyarlama.day());
display.print("/");
if (zamanAyarlama.month() < 10) {
display.print("0");
}
display.print(zamanAyarlama.month());
display.print("/");
display.print(zamanAyarlama.year());
display.print(" ");
if (zamanAyarlama.hour() < 10) {
display.print("0");
}
display.print(zamanAyarlama.hour());
display.print(":");
if (zamanAyarlama.minute() < 10) {
display.print("0");
}
display.print(zamanAyarlama.minute());
display.print(":");
if (zamanAyarlama.second() < 10) {
display.print("0");
}
display.print(zamanAyarlama.second());
display.setTextSize(2);
display.setCursor(0, 22);
display.print(zmnAyarMetni);
display.display();
}
void MetindenTariheAyarla(String ZamanMetni) {
if (ZamanMetni.length() > 18) {
tempStr = "";
tempStr += ZamanMetni[0];
tempStr += ZamanMetni[1];
tempStr;
if (StringSayiMi(tempStr)) {
ayrDay = tempStr.toInt(); //Day
if (ayrDay < 1 || 31 < ayrDay) {
MesajOLED("HATALI\nBiLGi!", 2, 0, 0, 2000);
mod = 0;
return;
}
tempStr = "";
tempStr += ZamanMetni[3];
tempStr += ZamanMetni[4];
tempStr;
if (StringSayiMi(tempStr)) {
ayrMonth = tempStr.toInt(); //Month
if (ayrMonth < 1 || 12 < ayrMonth) {
MesajOLED("HATALI\nBiLGi!", 2, 0, 0, 2000);
mod = 0;
return;
}
tempStr = "";
tempStr += ZamanMetni[6];
tempStr += ZamanMetni[7];
tempStr += ZamanMetni[8];
tempStr += ZamanMetni[9];
tempStr;
if (StringSayiMi(tempStr)) {
ayrYear = tempStr.toInt(); //Year
if (ayrYear < 2025) {
MesajOLED("HATALI\nBiLGi!", 2, 0, 0, 2000);
mod = 0;
return;
}
tempStr = "";
tempStr += ZamanMetni[11];
tempStr += ZamanMetni[12];
tempStr;
if (StringSayiMi(tempStr)) {
ayrHour = tempStr.toInt(); //Hour
if (ayrHour < 0 || 23 < ayrHour) {
MesajOLED("HATALI\nBiLGi!", 2, 0, 0, 2000);
mod = 0;
return;
}
tempStr = "";
tempStr += ZamanMetni[14];
tempStr += ZamanMetni[15];
tempStr;
if (StringSayiMi(tempStr)) {
ayrMinute = tempStr.toInt(); //Minute
if (ayrMinute < 0 || 59 < ayrMinute) {
MesajOLED("HATALI\nBiLGi!", 2, 0, 0, 2000);
mod = 0;
return;
}
tempStr = "";
tempStr += ZamanMetni[17];
tempStr += ZamanMetni[18];
tempStr;
if (StringSayiMi(tempStr)) {
ayrSecond = tempStr.toInt(); //Second
if (ayrSecond < 0 || 59 < ayrSecond) {
MesajOLED("HATALI\nBiLGi!", 2, 0, 0, 2000);
mod = 0;
return;
}
GercekZamanliSaat.adjust(DateTime(ayrYear, ayrMonth, ayrDay, ayrHour, ayrMinute, ayrSecond)); // yıl, ay, gün, saat, dakika, saniyeni ayarlanması
MesajOLED("SAAT TARiH\nAYARLANDI", 2, 0, 0, 2000);
mod = 0;
} else {
MesajOLED("HATALI\nBiLGi!", 2, 0, 0, 2000);
}
} else {
MesajOLED("HATALI\nBiLGi!", 2, 0, 0, 2000);
}
} else {
MesajOLED("HATALI\nBiLGi!", 2, 0, 0, 2000);
}
} else {
MesajOLED("HATALI\nBiLGi!", 2, 0, 0, 2000);
}
} else {
MesajOLED("HATALI\nBiLGi!", 2, 0, 0, 2000);
}
} else {
MesajOLED("HATALI\nBiLGi!", 2, 0, 0, 2000);
}
} else {
MesajOLED("Eksik\nBilgi!", 2, 0, 0, 2000);
mod = 0;
}
}
bool StringSayiMi(String girilenVeri) {
bool sayiMi = true;
for (int i = 0; i < girilenVeri.length(); i++) {
if (!isDigit(girilenVeri.charAt(i)) && !(i == 0 && girilenVeri.charAt(i) == '-')) {
sayiMi = false;
break;
}
}
return sayiMi;
}
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO: A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO: 2(SDA), 3(SCL), ...
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3D ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#include "lsm6dsm.h" // Dahili IMU kütüphanesi
// IMU (İvmeölçer) sensörünü başlatmak için bir LSM6DSM class'ı tanımlandı.
LSM6DSM IMU;
int sicaklik_degeri = 0.0;
#include <Deneyap_GercekZamanliSaat.h>
RTC GercekZamanliSaat;
DateTime now;
DateTime zamanAyarlama;
int zmnAyrImlec = 0;
String zmnAyarMetni = "__/__/____ __:__:__";
int ayrDay = 0;
int ayrMonth = 0;
long ayrYear = 0;
int ayrHour = 0;
int ayrMinute = 0;
int ayrSecond = 0;
String tempStr = "";
long tempInt = 0;
#include <Deneyap_DokunmatikTusTakimi.h>
Keypad Keypad;
int keyword;
#include "BluetoothSerial.h"
BluetoothSerial SerialBT;
String gelenYazi = "";
unsigned long timer1 = 0; //Zaman kesmesi gibi(!)
int mod = 0;
void MesajOLED(String mesaj = "Mesaj", int size = 1, int x = 0, int y = 0, int zaman = 1000, bool silinsinmi = true) {
display.clearDisplay();
display.setCursor(x, y);
display.setTextSize(size);
display.setTextColor(SSD1306_WHITE);
display.print(mesaj);
display.display();
delay(zaman);
if (silinsinmi) {
display.clearDisplay();
display.display();
}
}
void MesajHazirla(String mesaj = "Mesaj", int size = 1, int x = 0, int y = 0, bool gosterilsinmi = false) {
display.setCursor(x, y);
display.setTextSize(size);
display.setTextColor(SSD1306_WHITE);
display.print(mesaj);
if (gosterilsinmi) {
display.display();
}
}
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("- - - - - - - - - - - - - - - -");
delay(1000);
SerialBT.begin("DeneyapKart_01");
Serial.println("DeneyapKart_01 - Yayın başladı.");
Serial.println("- - - - - - - - - - - - - - - -");
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;)
; // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
//display.display();
//delay(2000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
display.display();
IMU.begin(); // IMU sensörümüzü başlatıldı.
delay(100);
//Gerçek Zamanlı Saat Modülü
if (!GercekZamanliSaat.begin()) {
delay(3000);
//Serial.println("I2C bağlantısı başarısız ");
while (1)
;
}
now = GercekZamanliSaat.now();
if (now.year() < 2025) {
GercekZamanliSaat.adjust(DateTime(2025, 6, 12, 20, 40, 0)); // yıl, ay, gün, saat, dakika, saniyeni ayarlanması
}
Keypad.begin(0x0E);
//pinMode(GPKEY, INPUT);
}
void loop() {
if (SerialBT.available()) {
gelenYazi = SerialBT.readString();
Serial.print("Gelen Yazı: ");
Serial.print(gelenYazi);
SerialBT.print(gelenYazi);
String tempYazi = gelenYazi.substring(0, gelenYazi.length() - 2);
MesajOLED(tempYazi, 1, 0, 0, 2000);
if (tempYazi == "Zaman Ayarla") {
if (mod != 1) {
mod = 1;
}
} else if (tempYazi == "iptal" || tempYazi == "iptal" || tempYazi == "İPTAL") {
mod = 0;
} else if (mod == 1) {
MetindenTariheAyarla(tempYazi);
}
gelenYazi = "";
}
if (Serial.available()) {
gelenYazi = Serial.readString();
Serial.print("Gelen Yazı: ");
Serial.print(gelenYazi);
String tempYazi = gelenYazi.substring(0, gelenYazi.length() - 1);
MesajOLED(tempYazi, 1, 0, 0, 2000);
if (tempYazi == "Zaman Ayarla") {
if (mod != 1) {
mod = 1;
}
} else if (tempYazi == "iptal" || tempYazi == "iptal" || tempYazi == "İPTAL") {
mod = 0;
} else if (mod == 1) {
MetindenTariheAyarla(tempYazi);
}
gelenYazi = "";
}
// if (!digitalRead(D8)) {
// zmnAyrImlec = 0;
// mod = 0;
// zmnAyarMetni = "__/__/____ __:__:__";
// }
switch (mod) {
case 0:
Timer();
keyword = Keypad.KeypadRead();
if (keyword != 0xFF) {
switch (keyword) {
case 0:
break;
case 1:
mod = 1;
zamanAyarlama = now;
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
}
}
break;
case 1:
ZamanAyariEkrani();
if (zmnAyrImlec == 2) {
tempStr = "";
tempStr += zmnAyarMetni[0];
tempStr += zmnAyarMetni[1];
tempInt = tempStr.toInt();
if ((tempInt < 1) || (31 < tempInt)) {
zmnAyarMetni[0] = '_';
zmnAyarMetni[1] = '_';
zmnAyrImlec = 0;
if (tempInt == 99) {
mod = 0;
zmnAyarMetni = "__/__/____ __:__:__";
zmnAyrImlec = 0;
}
} else {
ayrDay = tempInt;
zmnAyrImlec++;
}
} else if (zmnAyrImlec == 5) {
tempStr = "";
tempStr += zmnAyarMetni[3];
tempStr += zmnAyarMetni[4];
tempInt = tempStr.toInt();
if ((tempInt < 1) || (12 < tempInt)) {
zmnAyarMetni[3] = '_';
zmnAyarMetni[4] = '_';
zmnAyrImlec = 3;
if (tempInt == 99) {
mod = 0;
zmnAyarMetni = "__/__/____ __:__:__";
zmnAyrImlec = 0;
}
} else {
ayrMonth = tempInt;
zmnAyrImlec++;
}
} else if (zmnAyrImlec == 10) {
tempStr = "";
tempStr += zmnAyarMetni[6];
tempStr += zmnAyarMetni[7];
tempStr += zmnAyarMetni[8];
tempStr += zmnAyarMetni[9];
tempInt = tempStr.toInt();
if (tempInt < 2025) {
zmnAyarMetni[6] = '_';
zmnAyarMetni[7] = '_';
zmnAyarMetni[8] = '_';
zmnAyarMetni[9] = '_';
zmnAyrImlec = 6;
if (tempInt == 9999) {
mod = 0;
zmnAyarMetni = "__/__/____ __:__:__";
zmnAyrImlec = 0;
}
} else {
ayrYear = tempInt;
zmnAyrImlec++;
}
} else if (zmnAyrImlec == 13) {
tempStr = "";
tempStr += zmnAyarMetni[11];
tempStr += zmnAyarMetni[12];
tempInt = tempStr.toInt();
if ((tempInt < 0) || (23 < tempInt)) {
zmnAyarMetni[11] = '_';
zmnAyarMetni[12] = '_';
zmnAyrImlec = 11;
if (tempInt == 99) {
mod = 0;
zmnAyarMetni = "__/__/____ __:__:__";
zmnAyrImlec = 0;
}
} else {
ayrHour = tempInt;
zmnAyrImlec++;
}
} else if (zmnAyrImlec == 16) {
tempStr = "";
tempStr += zmnAyarMetni[14];
tempStr += zmnAyarMetni[15];
tempInt = tempStr.toInt();
if ((tempInt < 0) || (59 < tempInt)) {
zmnAyarMetni[14] = '_';
zmnAyarMetni[15] = '_';
zmnAyrImlec = 14;
if (tempInt == 99) {
mod = 0;
zmnAyarMetni = "__/__/____ __:__:__";
zmnAyrImlec = 0;
}
} else {
ayrMinute = tempInt;
zmnAyrImlec++;
}
} else if (zmnAyrImlec == 19) {
tempStr = "";
tempStr += zmnAyarMetni[17];
tempStr += zmnAyarMetni[18];
tempInt = tempStr.toInt();
if ((tempInt < 0) || (59 < tempInt)) {
zmnAyarMetni[17] = '_';
zmnAyarMetni[18] = '_';
zmnAyrImlec = 17;
if (tempInt == 99) {
mod = 0;
zmnAyarMetni = "__/__/____ __:__:__";
zmnAyrImlec = 0;
}
} else {
ayrSecond = tempInt;
GercekZamanliSaat.adjust(DateTime(ayrYear, ayrMonth, ayrDay, ayrHour, ayrMinute, ayrSecond)); // yıl, ay, gün, saat, dakika, saniyeni ayarlanması
zmnAyrImlec = 0;
mod = 0;
zmnAyarMetni = "__/__/____ __:__:__";
zmnAyrImlec = 0;
}
}
keyword = Keypad.KeypadRead();
if (keyword != 0xFF) {
switch (keyword) {
case 0:
zmnAyarMetni[zmnAyrImlec] = '0';
zmnAyrImlec++;
break;
case 1:
zmnAyarMetni[zmnAyrImlec] = '1';
zmnAyrImlec++;
break;
case 2:
zmnAyarMetni[zmnAyrImlec] = '2';
zmnAyrImlec++;
break;
case 3:
zmnAyarMetni[zmnAyrImlec] = '3';
zmnAyrImlec++;
break;
case 4:
zmnAyarMetni[zmnAyrImlec] = '4';
zmnAyrImlec++;
break;
case 5:
zmnAyarMetni[zmnAyrImlec] = '5';
zmnAyrImlec++;
break;
case 6:
zmnAyarMetni[zmnAyrImlec] = '6';
zmnAyrImlec++;
break;
case 7:
zmnAyarMetni[zmnAyrImlec] = '7';
zmnAyrImlec++;
break;
case 8:
zmnAyarMetni[zmnAyrImlec] = '8';
zmnAyrImlec++;
break;
case 9:
zmnAyarMetni[zmnAyrImlec] = '9';
zmnAyrImlec++;
break;
}
}
break;
case 2:
keyword = Keypad.KeypadRead();
if (keyword != 0xFF) {
switch (keyword) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
}
}
break;
case 3:
keyword = Keypad.KeypadRead();
if (keyword != 0xFF) {
switch (keyword) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
}
}
break;
case 4:
keyword = Keypad.KeypadRead();
if (keyword != 0xFF) {
switch (keyword) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
}
}
break;
case 5:
keyword = Keypad.KeypadRead();
if (keyword != 0xFF) {
switch (keyword) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
}
}
break;
}
}
void Timer() {
if (millis() - timer1 >= 1000 || millis() < timer1) {
timer1 = millis();
now = GercekZamanliSaat.now();
sicaklik_degeri = round(IMU.readTempC());
display.clearDisplay();
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0, 0);
display.print(sicaklik_degeri);
display.print(" C");
display.drawCircle(30, 4, 3, SSD1306_WHITE);
display.drawCircle(30, 4, 4, SSD1306_WHITE);
display.setCursor(0, 22);
if (now.day() < 10) {
display.print("0");
}
display.print(now.day());
display.print("/");
if (now.month() < 10) {
display.print("0");
}
display.print(now.month());
display.print("/");
display.print(now.year());
display.setCursor(0, 44);
if (now.hour() < 10) {
display.print("0");
}
display.print(now.hour());
display.print(":");
if (now.minute() < 10) {
display.print("0");
}
display.print(now.minute());
display.print(":");
if (now.second() < 10) {
display.print("0");
}
display.print(now.second());
display.display();
}
}
void ZamanAyariEkrani() {
display.clearDisplay();
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(8, 5);
if (zamanAyarlama.day() < 10) {
display.print("0");
}
display.print(zamanAyarlama.day());
display.print("/");
if (zamanAyarlama.month() < 10) {
display.print("0");
}
display.print(zamanAyarlama.month());
display.print("/");
display.print(zamanAyarlama.year());
display.print(" ");
if (zamanAyarlama.hour() < 10) {
display.print("0");
}
display.print(zamanAyarlama.hour());
display.print(":");
if (zamanAyarlama.minute() < 10) {
display.print("0");
}
display.print(zamanAyarlama.minute());
display.print(":");
if (zamanAyarlama.second() < 10) {
display.print("0");
}
display.print(zamanAyarlama.second());
display.setTextSize(2);
display.setCursor(0, 22);
display.print(zmnAyarMetni);
display.display();
}
void MetindenTariheAyarla(String ZamanMetni) {
if (ZamanMetni.length() > 18) {
tempStr = "";
tempStr += ZamanMetni[0];
tempStr += ZamanMetni[1];
tempStr;
if (StringSayiMi(tempStr)) {
ayrDay = tempStr.toInt(); //Day
if (ayrDay < 1 || 31 < ayrDay) {
MesajOLED("HATALI\nBiLGi!", 2, 0, 0, 2000);
mod = 0;
return;
}
tempStr = "";
tempStr += ZamanMetni[3];
tempStr += ZamanMetni[4];
tempStr;
if (StringSayiMi(tempStr)) {
ayrMonth = tempStr.toInt(); //Month
if (ayrMonth < 1 || 12 < ayrMonth) {
MesajOLED("HATALI\nBiLGi!", 2, 0, 0, 2000);
mod = 0;
return;
}
tempStr = "";
tempStr += ZamanMetni[6];
tempStr += ZamanMetni[7];
tempStr += ZamanMetni[8];
tempStr += ZamanMetni[9];
tempStr;
if (StringSayiMi(tempStr)) {
ayrYear = tempStr.toInt(); //Year
if (ayrYear < 2025) {
MesajOLED("HATALI\nBiLGi!", 2, 0, 0, 2000);
mod = 0;
return;
}
tempStr = "";
tempStr += ZamanMetni[11];
tempStr += ZamanMetni[12];
tempStr;
if (StringSayiMi(tempStr)) {
ayrHour = tempStr.toInt(); //Hour
if (ayrHour < 0 || 23 < ayrHour) {
MesajOLED("HATALI\nBiLGi!", 2, 0, 0, 2000);
mod = 0;
return;
}
tempStr = "";
tempStr += ZamanMetni[14];
tempStr += ZamanMetni[15];
tempStr;
if (StringSayiMi(tempStr)) {
ayrMinute = tempStr.toInt(); //Minute
if (ayrMinute < 0 || 59 < ayrMinute) {
MesajOLED("HATALI\nBiLGi!", 2, 0, 0, 2000);
mod = 0;
return;
}
tempStr = "";
tempStr += ZamanMetni[17];
tempStr += ZamanMetni[18];
tempStr;
if (StringSayiMi(tempStr)) {
ayrSecond = tempStr.toInt(); //Second
if (ayrSecond < 0 || 59 < ayrSecond) {
MesajOLED("HATALI\nBiLGi!", 2, 0, 0, 2000);
mod = 0;
return;
}
GercekZamanliSaat.adjust(DateTime(ayrYear, ayrMonth, ayrDay, ayrHour, ayrMinute, ayrSecond)); // yıl, ay, gün, saat, dakika, saniyeni ayarlanması
MesajOLED("SAAT TARiH\nAYARLANDI", 2, 0, 0, 2000);
mod = 0;
} else {
MesajOLED("HATALI\nBiLGi!", 2, 0, 0, 2000);
}
} else {
MesajOLED("HATALI\nBiLGi!", 2, 0, 0, 2000);
}
} else {
MesajOLED("HATALI\nBiLGi!", 2, 0, 0, 2000);
}
} else {
MesajOLED("HATALI\nBiLGi!", 2, 0, 0, 2000);
}
} else {
MesajOLED("HATALI\nBiLGi!", 2, 0, 0, 2000);
}
} else {
MesajOLED("HATALI\nBiLGi!", 2, 0, 0, 2000);
}
} else {
MesajOLED("Eksik\nBilgi!", 2, 0, 0, 2000);
mod = 0;
}
}
bool StringSayiMi(String girilenVeri) {
bool sayiMi = true;
for (int i = 0; i < girilenVeri.length(); i++) {
if (!isDigit(girilenVeri.charAt(i)) && !(i == 0 && girilenVeri.charAt(i) == '-')) {
sayiMi = false;
break;
}
}
return sayiMi;
}