#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "MYPIN.h"
#include <SPI.h>
#include "max6675.h"
#include <PID_v1.h> // PID লাইব্রেরি ইনক্লুড করুন
const int thermoDO = 12;
const int thermoCS = 11;
const int thermoCLK = 13;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
// PID constants
double Kp = 2.0;
double Ki = 5.0;
double Kd = 1.0;
// Variables
double Setpoint = 70.0; // প্রেরণ তাপমাত্রা (সেলসিয়াস)
double Input, Output;
MYPIN mypin;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define OKBTN myPin.readPIN(3)
const int pinUp = 1, pinDown = 2, pinOK = 3, pinCancel = 0;
const char* menuLevel1[] = {
"Output State", "Input State", "Add", "Option 4", "Option 5", "Exit"
};
const char* menuLevel2[][4] = {
{"Option 1.1", "Option 1.2", "Option 1.3", "Back"},
{"Option 2.1", "Option 2.2", "Option 2.3", "Back"},
{"Option 3.1", "Option 3.2", "Option 3.3", "Back"}
};
byte arrowUp[8] = {B00100, B01110, B11111, B00100, B00100, B00000, B00000, B00000};
byte arrowDown[8] = {B00000, B00000, B00100, B00100, B11111, B01110, B00100, B00000};
byte arrowSelection[8] = {B00000, B10000, B11000, B11111, B11111, B11000, B10000, B00000};
byte arrowBack[8] = {B00000, B00100, B01100, B11111, B11111, B01100, B00100, B00000};
byte arrowExit[8] = {B00000, B00100, B01110, B11111, B01110, B00100, B00000, B00000};
int selectionLevel1 = 0, currentOffsetLevel1 = 0, selectionLevel2 = 0, currentOffsetLevel2 = 0, currentLevel = 1;
void setup() {
lcd.init();
mypin.output(1, true); // Set bit 5 to HIGH
//mypin.mypin;
lcd.backlight();
lcd.createChar(0, arrowUp);
lcd.createChar(1, arrowDown);
lcd.createChar(2, arrowSelection);
lcd.createChar(3, arrowBack);
lcd.createChar(4, arrowExit);
showMenuLevel1();
}
void loop() {
checkButtonPresses();
delay(00);
}
void checkButtonPresses() {
if (mypin.readPIN(pinUp) == LOW) {
moveSelection(-1);
delay(50); // ডেলে ব্যবহার করা হয়েছে সঠিক স্রোত রক্ষার জন্য
}
if (mypin.readPIN(pinDown) == LOW) {
moveSelection(1);
delay(50); // ডেলে ব্যবহার করা হয়েছে সঠিক স্রোত রক্ষার জন্য
}
if (mypin.readPIN(pinOK) == LOW) {
selectMenu();
delay(50); // ডেলে ব্যবহার করা হয়েছে সঠিক স্রোত রক্ষার জন্য
}
if (mypin.readPIN(pinCancel) == LOW && currentLevel == 2) {
currentLevel = 1;
showMenuLevel1();
delay(50); // ডেলে ব্যবহার করা হয়েছে সঠিক স্রোত রক্ষার জন্য
}
}
void showMenu(int level, const char** menu, int selection, int currentOffset) {
lcd.clear();
for (int i = 0; i < 2; i++) {
int index = currentOffset + i;
if (index >= (level == 1 ? sizeof(menuLevel1) / sizeof(menuLevel1[0]) : sizeof(menuLevel2[selectionLevel1]) / sizeof(menuLevel2[selectionLevel1][0]))) break;
lcd.setCursor(0, i);
if (selection == index) {
lcd.write(byte((level == 1 && strcmp(menu[index], "Exit") == 0) ? 4 : (level == 2 && strcmp(menu[index], "Back") == 0) ? 3 : 2));
} else {
lcd.print(" ");
}
lcd.print(menu[index]);
if (i == 0 && currentOffset > 0) lcd.setCursor(15, 0), lcd.write(byte(0));
else if (i == 1 && index < (level == 1 ? sizeof(menuLevel1) / sizeof(menuLevel1[0]) : sizeof(menuLevel2[selectionLevel1]) / sizeof(menuLevel2[selectionLevel1][0])) - 1) lcd.setCursor(15, 1), lcd.write(byte(1));
}
}
void showMenuLevel1() {
showMenu(1, menuLevel1, selectionLevel1, currentOffsetLevel1);
}
void showMenuLevel2() {
showMenu(2, menuLevel2[selectionLevel1], selectionLevel2, currentOffsetLevel2);
}
void moveSelection(int direction) {
if (currentLevel == 1) {
selectionLevel1 = (selectionLevel1 + direction + sizeof(menuLevel1) / sizeof(menuLevel1[0])) % (sizeof(menuLevel1) / sizeof(menuLevel1[0]));
currentOffsetLevel1 = (selectionLevel1 / 2) * 2;
showMenuLevel1();
} else {
selectionLevel2 = (selectionLevel2 + direction + sizeof(menuLevel2[selectionLevel1]) / sizeof(menuLevel2[selectionLevel1][0])) % (sizeof(menuLevel2[selectionLevel1]) / sizeof(menuLevel2[selectionLevel1][0]));
currentOffsetLevel2 = (selectionLevel2 / 2) * 2;
showMenuLevel2();
}
}
void selectMenu() {
if (currentLevel == 1) {
if (selectionLevel1 == sizeof(menuLevel1) / sizeof(menuLevel1[0]) - 1) {
lcd.clear();
lcd.print("Prog. terminated");
while (true);
}
currentLevel = 2;
selectionLevel2 = 0;
currentOffsetLevel2 = 0;
showMenuLevel2();
} else {
if (selectionLevel2 == sizeof(menuLevel2[selectionLevel1]) / sizeof(menuLevel2[selectionLevel1][0]) - 1) {
currentLevel = 1;
showMenuLevel1();
} else {
executeFunction(selectionLevel1, selectionLevel2);
}
}
}
void executeFunction(int indexLevel1, int indexLevel2) {
lcd.clear();
lcd.print("Executing: ");
lcd.setCursor(0, 1);
lcd.print(menuLevel2[indexLevel1][indexLevel2]);
delay(3000);
lcd.clear();
lcd.print("Function done");
delay(2000);
showMenuLevel2();
}
(click to edit)
(click to edit)
(click to edit)
(click to edit)
(click to edit)
(click to edit)