Sorry, all code is below:
#include "DHT.h"
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#include "RTClib.h"
// Define the connections pins:
#define CLK 2
#define DIO 3
const int buttonPin1=9;
const int buttonPin2=10;
const int buttonPin3=11;
// Create rtc and display object:
RTC_DS3231 rtc;
// Declare LCD object for software SPI
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
String extractLastTwoChars(const String &str) {//sağdan trimleme için fonksiyon yazılıyor
// Check if the string has at least two characters
if (str.length() >= 2) {
// Extract the last two characters
return str.substring(str.length() - 2);
} else {
// Handle the case where the string has less than two characters
return str;
}
}
void setup() {
Serial.begin(9600);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
Serial.println("DHRxx test!");
delay(3000);
// Check if RTC is connected correctly:
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
// Check if the RTC lost power and if so, set the time:
if (rtc.lostPower()) {
Serial.println("RTC lost power, lets set the time!");
rtc.adjust(DateTime(2024, 1, 10, 15, 28, 05));
}
dht.begin();
// Initialize Display
display.begin();
display.setContrast(57);
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("DHT sensöründen veriler okunamadı");
return;
}
float hic = dht.computeHeatIndex(t, h, false);
display.clearDisplay();
display.setTextColor(BLACK);
display.setCursor(0, 0);
display.setTextSize(0.5);
display.println(String(t) + "*C "+ String(h) + "%");
display.println("HeatIn:" + String(hic) + "*C");
DateTime now = rtc.now();
String originalString = String(now.year(), DEC);
String lastTwoChars = extractLastTwoChars(originalString);
if (now.hour() < 10) {
if (now.minute()<10){
display.println("0" + String(now.hour()) + ((now.second() % 2 == 0) ? " " : ":") + "0"+String(now.minute())+" "+String(now.day(), DEC) + "." + String(now.month(), DEC) + "." + lastTwoChars);
} else {
display.println("0" + String(now.hour()) + ((now.second() % 2 == 0) ? " " : ":") + String(now.minute())+" "+String(now.day(), DEC) + "." + String(now.month(), DEC) + "." + lastTwoChars);
}
} else {
if (now.minute()<10){
display.println(String(now.hour()) + ((now.second() % 2 == 0) ? " " : ":") + "0" + String(now.minute())+" "+String(now.day(), DEC) + "." + String(now.month(), DEC) + "." + lastTwoChars);
} else{
display.println(String(now.hour()) + ((now.second() % 2 == 0) ? " " : ":") + String(now.minute())+" "+String(now.day(), DEC) + "." + String(now.month(), DEC) + "." + lastTwoChars);
}
}
int durum1= digitalRead(buttonPin1);
int durum2=digitalRead(buttonPin2);
int durum3=digitalRead(buttonPin3);
if (durum1 == HIGH) {
display.println("1. buton");
}
if (durum2 == HIGH) {
Serial.println("2. buton");
}
if (durum3 == HIGH) {
Serial.println("3. buton");
}
display.display();
delay(1000);
}