#include <MAX6675_Thermocouple.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <RotaryEncoder.h>
// Pin tanımlamaları
int thermoDO = 2;
int thermoCS = 3;
int thermoCLK = 4;
const int button1Pin = 7;
const int button4Pin = 10;
const int relayPin = 11;
const int buzzerpin = 12;
const int encoderPinA = 5;
const int encoderPinB = 6;
// Kütüphane ve nesne oluşturma
MAX6675_Thermocouple thermocouple(thermoCLK, thermoCS, thermoDO);
LiquidCrystal_I2C lcd(0x27, 20, 4);
RotaryEncoder encoder(encoderPinA, encoderPinB);
int setPoint = 0;
int ayarZaman = 0;
unsigned long baslangicZamani = 0;
bool settingMode = false;
bool isAyarIsSelected = true; // true: ayar ısı, false: ayar zaman
bool relayActive = false;
bool buzzeractive = false;
bool countdownStarted = false;
void setup() {
pinMode(button1Pin, INPUT_PULLUP);
pinMode(button4Pin, INPUT_PULLUP);
pinMode(relayPin, OUTPUT);
pinMode(buzzerpin, OUTPUT);
lcd.init();
lcd.clear();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Mevcut ISI :");
lcd.setCursor(1, 1);
lcd.print("Ayar ISI : >");
lcd.setCursor(1, 2);
lcd.print("Ayar Zaman:");
lcd.setCursor(0, 3);
lcd.print("Gecen Zaman:");
encoder.setPosition(0); // Encoder'ın başlangıç pozisyonu
}
void loop() {
double temp = thermocouple.readCelsius();
lcd.setCursor(12, 0);
lcd.print(temp);
delay (150);
lcd.print("'C");
lcd.setCursor(12, 1);
lcd.print(setPoint);
lcd.print("'C");
lcd.setCursor(12, 2);
lcd.print(ayarZaman / 60);
lcd.print("dk");
lcd.print(ayarZaman % 60);
lcd.setCursor(18, 2);
lcd.print("sn");
unsigned long currentTime = millis();
int gecenZaman = (currentTime - baslangicZamani) / 1000;
if (!countdownStarted) {
gecenZaman = 0;
}
lcd.setCursor(12, 3);
lcd.print(gecenZaman / 60);
lcd.print("dk");
lcd.print(gecenZaman % 60);
lcd.setCursor(18, 3);
lcd.print("sn");
if (digitalRead(button1Pin) == LOW) {
delay(1000);
if (digitalRead(button1Pin) == LOW) {
isAyarIsSelected = !isAyarIsSelected;
if (isAyarIsSelected) {
lcd.setCursor(0, 1);
lcd.print(">");
lcd.setCursor(0, 2);
lcd.print(" ");
} else {
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 2);
lcd.print(">");
}
delay(300);
}
}
encoder.tick();
int newPos = encoder.getPosition();
static int oldPos = 0;
if (newPos != oldPos) {
if (newPos > oldPos) {
if (isAyarIsSelected) {
setPoint++;
} else {
ayarZaman++;
}
} else {
if (isAyarIsSelected) {
setPoint--;
} else {
ayarZaman--;
}
}
oldPos = newPos;
}
if (digitalRead(button4Pin) == LOW) {
delay(200);
if (digitalRead(button4Pin) == LOW) {
buzzeractive = true;
relayActive = true;
baslangicZamani = millis();
countdownStarted = true;
delay(300);
}
}
if (buzzeractive) {
if (gecenZaman == ayarZaman) {
digitalWrite(buzzerpin, HIGH);
delay(3000);
digitalWrite(buzzerpin, LOW);
} else {
digitalWrite(buzzerpin, LOW);
}
}
if (relayActive) {
if (temp < setPoint && gecenZaman < ayarZaman) {
digitalWrite(relayPin, HIGH);
} else {
digitalWrite(relayPin, LOW);
if (gecenZaman >= ayarZaman) {
relayActive = false;
countdownStarted = false;
}
}
} else {
digitalWrite(relayPin, LOW);
}
}