#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
#include <MAX6675_Thermocouple.h>
// Pin tanımlamaları
const int rotaryCLK = 6;
const int rotaryDT = 5;
const int rotarySW = 4;
const int startButton = 7;
const int thermoSO = 6;
const int thermoCS = 9;
const int thermoSCK = 8;
const int buzzer = 11;
const int relay = 10;
// Değişkenler
int currentProfile = 0;
int currentStep = 0;
int rotaryPos = 0;
bool rotaryPressed = false;
bool startPressed = false;
bool inMenu = false;
bool inProfileMenu = false;
// LCD ve MAX6675 nesneleri
LiquidCrystal_I2C lcd(0x27, 20, 4);
MAX6675_Thermocouple thermocouple(thermoSCK, thermoCS, thermoSO);
// Profil yapısı
struct Profile {
float temperature[10];
unsigned long duration[10];
};
Profile profiles[10];
void setup() {
// Pin modları
pinMode(rotaryCLK, INPUT);
pinMode(rotaryDT, INPUT);
pinMode(rotarySW, INPUT_PULLUP);
pinMode(startButton, INPUT_PULLUP);
pinMode(buzzer, OUTPUT);
pinMode(relay, OUTPUT);
// LCD başlatma
lcd.init();
lcd.backlight();
// EEPROM'dan profilleri yükle
loadProfiles();
// Başlangıç ekranı
lcd.setCursor(0, 0);
lcd.print("BGA Makinesi");
lcd.setCursor(0, 1);
lcd.print("Profil: ");
lcd.print(currentProfile + 1);
}
void loop() {
// Rotary encoder kontrolü
rotaryControl();
// Start butonu kontrolü
if (digitalRead(startButton) == LOW && !startPressed) {
startPressed = true;
if (!inMenu) {
startProcess();
}
} else if (digitalRead(startButton) == HIGH) {
startPressed = false;
}
// LCD güncelleme
if (!inMenu) {
updateMainScreen();
}
}
void rotaryControl() {
static int lastStateCLK = digitalRead(rotaryCLK);
int currentStateCLK = digitalRead(rotaryCLK);
if (currentStateCLK != lastStateCLK && currentStateCLK == 1) {
if (digitalRead(rotaryDT) != currentStateCLK) {
rotaryPos--;
} else {
rotaryPos++;
}
rotaryPos = constrain(rotaryPos, 0, 9);
if (inMenu) {
if (inProfileMenu) {
currentStep = rotaryPos;
} else {
currentProfile = rotaryPos;
}
}
}
lastStateCLK = currentStateCLK;
if (digitalRead(rotarySW) == LOW && !rotaryPressed) {
rotaryPressed = true;
if (!inMenu) {
inMenu = true;
inProfileMenu = false;
rotaryPos = 0;
} else if (inMenu && !inProfileMenu) {
inProfileMenu = true;
rotaryPos = 0;
} else if (inProfileMenu) {
saveProfiles();
inProfileMenu = false;
inMenu = false;
}
} else if (digitalRead(rotarySW) == HIGH) {
rotaryPressed = false;
}
if (inMenu) {
updateMenuScreen();
}
}
void startProcess() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Isitma Basladi");
for (int i = 0; i < 10; i++) {
float targetTemp = profiles[currentProfile].temperature[i];
unsigned long duration = profiles[currentProfile].duration[i];
unsigned long startTime = millis();
while (thermocouple.readCelsius() < targetTemp && (millis() - startTime) < duration) {
digitalWrite(relay, HIGH);
delay(100);
updateMainScreen();
}
digitalWrite(relay, LOW);
delay(1000); // Isıtma adımları arası bekleme
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Isitma Tamamlandi");
digitalWrite(buzzer, HIGH);
delay(1000);
digitalWrite(buzzer, LOW);
}
void updateMainScreen() {
lcd.setCursor(0, 0);
lcd.print("Profil: ");
lcd.print(currentProfile + 1);
lcd.print(" Adim: ");
lcd.print(currentStep + 1);
lcd.setCursor(0, 1);
lcd.print("Sicaklik: ");
lcd.print(thermocouple.readCelsius());
lcd.print("C");
lcd.setCursor(0, 2);
lcd.print("Hedef: ");
lcd.print(profiles[currentProfile].temperature[currentStep]);
lcd.print("C");
lcd.setCursor(0, 3);
lcd.print("Geri Sayim: ");
lcd.print((profiles[currentProfile].duration[currentStep] - (millis() % profiles[currentProfile].duration[currentStep])) / 1000);
lcd.print("s");
}
void updateMenuScreen() {
lcd.clear();
if (!inProfileMenu) {
lcd.setCursor(0, 0);
lcd.print("Profil Secimi");
lcd.setCursor(0, 1);
lcd.print("Profil: ");
lcd.print(currentProfile + 1);
} else {
lcd.setCursor(0, 0);
lcd.print("Adim: ");
lcd.print(currentStep + 1);
lcd.setCursor(0, 1);
lcd.print("Sicaklik: ");
lcd.print(profiles[currentProfile].temperature[currentStep]);
lcd.print("C");
lcd.setCursor(0, 2);
lcd.print("Sure: ");
lcd.print(profiles[currentProfile].duration[currentStep] / 1000);
lcd.print("s");
}
}
void loadProfiles() {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
profiles[i].temperature[j] = EEPROM.read(i * 40 + j * 4);
profiles[i].duration[j] = EEPROM.read(i * 40 + j * 4 + 2) * 1000UL;
}
}
}
void saveProfiles() {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
EEPROM.write(i * 40 + j * 4, profiles[i].temperature[j]);
EEPROM.write(i * 40 + j * 4 + 2, profiles[i].duration[j] / 1000UL);
}
}
}