User Interface Codes:
********************************
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); //0x3f 0x27
uint8_t arrow[8] = {0x0, 0x04 , 0x06, 0x1f, 0x06, 0x04, 0x00, 0x00};
int counter = 0;
int page = 1;
int Ready = 1;
int submenu = 0;
int subsubmenu = 0;
int subsubsubmenu =0;
int last_counter = 0;
bool clk_State;
bool Last_State;
bool dt_State;
int pushed = 0;
int dubak = 0;
int buzzer = 6;
int var = 0;
#define push 10
#define RELAY1 7 //ac
#define RELAY2 5 //kapa
#define RELAY3 4 //mod
#define RELAY4 3 //sure
void setup() {
pinMode (push, OUTPUT);
pinMode (buzzer, OUTPUT);
pinMode (RELAY1, OUTPUT);
pinMode (RELAY2, OUTPUT);
pinMode (RELAY3, OUTPUT);
pinMode (RELAY4, OUTPUT);
lcd.init();
lcd.backlight();
lcd.home();
PCICR |= (1 << PCIE0);
PCMSK0 |= (1 << PCINT0);
PCMSK0 |= (1 << PCINT1);
DDRB &= B11111100;
Last_State = (PINB & B00000001);
lcd.clear();
lcd.setCursor(0, 0);
(0);
lcd.print(" Circle Electronic");
(0);
lcd.setCursor(0, 1);
lcd.print(" PLC User Interface ");
lcd.setCursor(11, 3);
lcd.print("Ver 1.24");
//openingMusic();
delay(1600);
lcd.clear();
lcd.setCursor(7, 0);
lcd.print("Circle");
lcd.setCursor(3, 1);
lcd.print("User Interface");
lcd.setCursor(0, 2);
lcd.print(" >English");
lcd.setCursor(0, 3);
lcd.print(" Turkce");
}
void loop() {
if ((last_counter > counter) || (last_counter < counter) || pushed)
{
Ready = 1;
if (submenu == 0)
{
if (0 <= counter && counter < 4)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(7, 0);
lcd.print("Circle");
lcd.setCursor(3, 1);
lcd.print("User Interface");
lcd.setCursor(0, 2);
lcd.print(" >English");
lcd.setCursor(0, 3);
lcd.print(" Turkce");
page = 1;
if (pushed)
{
pushed = 0;
}
}
if (5 < counter && counter < 10)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(7, 0);
lcd.print("Circle");
lcd.setCursor(3, 1);
lcd.print("User Interface");
lcd.setCursor(0, 2);
lcd.print(" English");
lcd.setCursor(0, 3);
lcd.print(" >Turkce");
page = 2;
if (pushed)
{
pushed = 0;
}
}
}
//submenu0end
if (subsubmenu == 1)
{
if (0 <= counter && counter < 5)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(">Open the Gate");//ac kapa
lcd.setCursor(0, 1);
lcd.print("Close the Gate");
lcd.setCursor(0, 2);
lcd.print("Set Closing Time");
lcd.setCursor(0, 3);
lcd.print("Change the Mode");
dubak = 1;
if (pushed)
{
pushed = 0;
}
}
if (5 <= counter && counter < 10)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Open the Gate");//ac kapa
lcd.setCursor(0, 1);
lcd.print(">Close the Gate");
lcd.setCursor(0, 2);
lcd.print("Set Closing Time");
lcd.setCursor(0, 3);
lcd.print("Change the Mode");
dubak = 2;
if (pushed)
{
pushed = 0;
}
}
if (10 <= counter && counter < 15)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Open the Gate");//ac kapa
lcd.setCursor(0, 1);
lcd.print("Close the Gate");
lcd.setCursor(0, 2);
lcd.print(">Set Closing Time");
lcd.setCursor(0, 3);
lcd.print("Change the Mode");
dubak = 3;
if (pushed)
{
pushed = 0;
}
}
if (15 <= counter && counter < 20)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Open the Gate");//ac kapa
lcd.setCursor(0, 1);
lcd.print("Close the Gate");
lcd.setCursor(0, 2);
lcd.print("Set Closing Time");
lcd.setCursor(0, 3);
lcd.print(">Change the Mode");
dubak = 4;
if (pushed)
{
pushed = 0;
}
}
if (20 <= counter && counter < 25)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(">Back");//ac kapa
dubak = 5;
if (pushed)
{
pushed = 0;
}
}
}
if (subsubmenu == 2)
{
if (0 <= counter && counter < 5)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(">Kapiyi Ac");//ac kapa
lcd.setCursor(0, 1);
lcd.print("Kapiyi Kapat");
lcd.setCursor(0, 2);
lcd.print("Kapanma Zamanini Sec");
lcd.setCursor(0, 3);
lcd.print("Modu Degistir");
dubak = 1;
if (pushed)
{
pushed = 0;
}
}
if (5 <= counter && counter < 10)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Kapiyi Ac");//ac kapa
lcd.setCursor(0, 1);
lcd.print(">Kapiyi Kapat");
lcd.setCursor(0, 2);
lcd.print("Kapanma Zamanini Sec");
lcd.setCursor(0, 3);
lcd.print("Modu Degistir");
dubak = 2;
if (pushed)
{
pushed = 0;
}
}
if (10 <= counter && counter < 15)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Kapiyi Ac");//ac kapa
lcd.setCursor(0, 1);
lcd.print("Kapiyi Kapat");
lcd.setCursor(0, 2);
lcd.print(">Kapanma Zamanini Sec");
lcd.setCursor(0, 3);
lcd.print("Modu Degistir");
dubak = 3;
if (pushed)
{
pushed = 0;
}
}
if (15 <= counter && counter < 20)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Kapiyi Ac");//ac kapa
lcd.setCursor(0, 1);
lcd.print("Kapiyi Kapat");
lcd.setCursor(0, 2);
lcd.print("Kapanma Zamanini Sec");
lcd.setCursor(0, 3);
lcd.print(">Modu Degistir");
dubak = 4;
if (pushed)
{
pushed = 0;
}
}
if (20 <= counter && counter < 25)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(">Geri Don");//ac kapa
dubak = 5;
if (pushed)
{
pushed = 0;
}
}
}
//**********************************************************************************************************************************************************************
if (subsubsubmenu == 1) {
if (0 <= counter && counter < 5)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Are You Sure?");
lcd.setCursor(0, 1);
lcd.print(">Yes");
lcd.setCursor(0, 2);
lcd.print("No");
page = 1;
pushed = 0;
}
if (5 < counter && counter < 10)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Are You Sure?");
lcd.setCursor(0, 1);
lcd.print("Yes");
lcd.setCursor(0, 2);
lcd.print(">No");
page = 2;
pushed = 0;
}
if (10 < counter && counter < 15)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Are You Sure?");
lcd.setCursor(0, 1);
lcd.print("Yes");
lcd.setCursor(0, 2);
lcd.print(">No");
page = 2;
pushed = 0;
}
if (15 < counter && counter < 20)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Are You Sure?");
lcd.setCursor(0, 1);
lcd.print("Yes");
lcd.setCursor(0, 2);
lcd.print(">No");
page = 2;
pushed = 0;
}
}
if (subsubsubmenu == 2) {
if (0 <= counter && counter < 5)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Are You Sure?");
lcd.setCursor(0, 1);
lcd.print(">Yes");
lcd.setCursor(0, 2);
lcd.print("No");
page = 1;
pushed = 0;
}
if (5 < counter && counter < 10)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Are You Sure?");
lcd.setCursor(0, 1);
lcd.print("Yes");
lcd.setCursor(0, 2);
lcd.print(">No");
page = 2;
pushed = 0;
}
if (10 < counter && counter < 15)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Are You Sure?");
lcd.setCursor(0, 1);
lcd.print("Yes");
lcd.setCursor(0, 2);
lcd.print(">No");
page = 2;
pushed = 0;
}
if (15 < counter && counter < 20)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Are You Sure?");
lcd.setCursor(0, 1);
lcd.print("Yes");
lcd.setCursor(0, 2);
lcd.print(">No");
page = 2;
pushed = 0;
}
}
if (subsubsubmenu == 3) {
if (0 <= counter && counter < 5)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(">2 Seconds");
lcd.setCursor(0, 1);
lcd.print("5 Seconds");
lcd.setCursor(0, 2);
lcd.print("10 Seconds");
lcd.setCursor(0, 3);
lcd.print("20 Seconds");
page = 1;
pushed = 0;
}
if (5 < counter && counter < 10)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("2 Seconds");
lcd.setCursor(0, 1);
lcd.print(">5 Seconds");
lcd.setCursor(0, 2);
lcd.print("10 Seconds");
lcd.setCursor(0, 3);
lcd.print("20 Seconds");
page = 2;
pushed = 0;
}
if (10 < counter && counter < 15)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("2 Seconds");
lcd.setCursor(0, 1);
lcd.print("5 Seconds");
lcd.setCursor(0, 2);
lcd.print(">10 Seconds");
lcd.setCursor(0, 3);
lcd.print("20 Seconds");
page = 3;
pushed = 0;
}
if (15 < counter && counter < 20)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("2 Seconds");
lcd.setCursor(0, 1);
lcd.print("5 Seconds");
lcd.setCursor(0, 2);
lcd.print("10 Seconds");
lcd.setCursor(0, 3);
lcd.print(">20 Seconds");
page = 4;
pushed = 0;
}
}
if (subsubsubmenu == 4) {
if (0 <= counter && counter < 5)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(">Automatic Mode");
lcd.setCursor(0, 1);
lcd.print("Manuel Mode");
page = 1;
pushed = 0;
}
if (5 < counter && counter < 10)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Automatic Mode");
lcd.setCursor(0, 1);
lcd.print(">Manuel Mode");
page = 2;
pushed = 0;
}
}
if (subsubsubmenu == 5) {
if (0 <= counter && counter < 5)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Emin Misiniz?");
lcd.setCursor(0, 1);
lcd.print(">Evet");
lcd.setCursor(0, 2);
lcd.print("Hayir");
page = 1;
pushed = 0;
}
if (5 < counter && counter < 10)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Emin Misiniz?");
lcd.setCursor(0, 1);
lcd.print("Evet");
lcd.setCursor(0, 2);
lcd.print(">Hayir");
page = 2;
pushed = 0;
}
}
if (subsubsubmenu == 6) {
if (0 <= counter && counter < 5)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Emin Misiniz?");
lcd.setCursor(0, 1);
lcd.print(">Evet");
lcd.setCursor(0, 2);
lcd.print("Hayir");
page = 1;
pushed = 0;
}
if (5 < counter && counter < 10)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Emin Misiniz?");
lcd.setCursor(0, 1);
lcd.print("Evet");
lcd.setCursor(0, 2);
lcd.print(">Hayir");
page = 2;
pushed = 0;
}
}
if (subsubsubmenu == 7) {
if (0 <= counter && counter < 5)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(">2 Saniye");
lcd.setCursor(0, 1);
lcd.print("5 Saniye");
lcd.setCursor(0, 2);
lcd.print("10 Saniye");
lcd.setCursor(0, 3);
lcd.print("20 Saniye");
page = 1;
pushed = 0;
}
if (5 < counter && counter < 10)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("2 Saniye");
lcd.setCursor(0, 1);
lcd.print(">5 Saniye");
lcd.setCursor(0, 2);
lcd.print("10 Saniye");
lcd.setCursor(0, 3);
lcd.print("20 Saniye");
page = 2;
pushed = 0;
}
if (10 < counter && counter < 15)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("2 Saniye");
lcd.setCursor(0, 1);
lcd.print("5 Saniye");
lcd.setCursor(0, 2);
lcd.print(">10 Saniye");
lcd.setCursor(0, 3);
lcd.print("20 Saniye");
page = 3;
pushed = 0;
}
if (15 < counter && counter < 20)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("2 Saniye");
lcd.setCursor(0, 1);
lcd.print("5 Saniye");
lcd.setCursor(0, 2);
lcd.print("10 Saniye");
lcd.setCursor(0, 3);
lcd.print(">20 Saniye");
page = 4;
pushed = 0;
}
}
if (subsubsubmenu == 8) {
if (0 <= counter && counter < 5)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(">Otomatik Mod");
lcd.setCursor(0, 1);
lcd.print("Manuel Mod");
page = 1;
pushed = 0;
}
if (5 < counter && counter < 10)
{
var=1;
while(var==1){
buzzermenuaction();
break;
}
var=0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Otomatik Mod");
lcd.setCursor(0, 1);
lcd.print(">Manuel Mod");
page = 2;
pushed = 0;
}
}
}//end of the MENU prints on the LCD
last_counter = counter; //Save the value of the last state
//**********************************************************************************************************************************************************************
//Now we detect when we push the button
if (digitalRead(push))
{
if (subsubsubmenu == 1)
{
if (page == 1)
{
var=1;
while(var==1){
buzzersetup();
break;
}
var=0;
subsubsubmenu = 0;
subsubmenu = 0;
submenu=0;
dubak=0;
page=0;
counter = 1;
pushed = 0;
Ready = 0;
digitalWrite(RELAY1, HIGH);
delay(2000);
digitalWrite(RELAY1, LOW);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Gate is Opening...");
lcd.setCursor(0, 2);
lcd.print(" Wait ");
delay(4000);
}
if (page == 2)
{
var=1;
while(var==1){
buzzermenuclick();
break;
}
var=0;
subsubsubmenu = 0;
subsubmenu = 0;
submenu = 0;
dubak=0;
page=0;
counter = 0;
pushed = 0;
Ready = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Going Back... ");
lcd.setCursor(0, 2);
lcd.print(" Wait ");
delay(2000);
}
}
if (subsubsubmenu == 2)
{
if (page == 1)
{
var=1;
while(var==1){
buzzersetup();
break;
}
var=0;
subsubsubmenu = 0;
subsubmenu = 0;
submenu = 0;
dubak=0;
page=0;
counter = 1;
pushed = 0;
Ready = 0;
digitalWrite(RELAY2, HIGH);
delay(2000);
digitalWrite(RELAY2, LOW);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Gate is Closing");
lcd.setCursor(0, 2);
lcd.print(" Wait ");
delay(4000);
}
if (page == 2)
{
var=1;
while(var==1){
buzzermenuclick();
break;
}
var=0;
subsubsubmenu = 0;
subsubmenu = 0;
submenu = 0;
dubak=0;
page=0;
counter = 0;
pushed = 0;
Ready = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Going Back");
lcd.setCursor(0, 2);
lcd.print(" Wait ");
delay(4000);
}
}
if (subsubsubmenu == 3)
{
if (page == 1)
{
var=1;
while(var==1){
buzzersetup();
break;
}
var=0;
subsubsubmenu = 0;
subsubmenu = 0;
submenu = 0;
dubak=0;
page=0;
counter = 1;
pushed = 0;
Ready = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Closing Time 2 Sec Now");
lcd.setCursor(0, 2);
lcd.print(" Wait ");
digitalWrite(RELAY3, HIGH);
delay(2000);
digitalWrite(RELAY3, LOW);
delay(4000);
}
if (page == 2)
{
var=1;
while(var==1){
buzzersetup();
break;
}
var=0;
subsubsubmenu = 0;
subsubmenu = 0;
submenu = 0;
dubak=0;
page=0;
counter = 0;
pushed = 0;
Ready = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Closing Time 5 Sec Now");
lcd.setCursor(0, 2);
lcd.print(" Wait ");
digitalWrite(RELAY3, HIGH);
delay(5000);
digitalWrite(RELAY3, LOW);
delay(4000);
}
if (page == 3)
{
var=1;
while(var==1){
buzzersetup();
break;
}
var=0;
subsubsubmenu = 0;
subsubmenu = 0;
submenu = 0;
dubak=0;
page=0;
counter = 0;
pushed = 0;
Ready = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Closing Time 10 Sec Now");
lcd.setCursor(0, 2);
lcd.print(" Wait ");
digitalWrite(RELAY3, HIGH);
delay(10000);
digitalWrite(RELAY3, LOW);
delay(4000);
}
if (page == 4)
{
var=1;
while(var==1){
buzzersetup();
break;
}
var=0;
subsubsubmenu = 0;
subsubmenu = 0;
submenu = 0;
counter = 0;
dubak=0;
page=0;
pushed = 0;
Ready = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Closing Time 20 Sec Now");
lcd.setCursor(0, 2);
lcd.print(" Wait ");
digitalWrite(RELAY3, HIGH);
delay(20000);
digitalWrite(RELAY3, LOW);
delay(4000);
}
}
if (subsubsubmenu == 4)
{
if (page == 1)
{
var=1;
while(var==1){
buzzersetup();
break;
}
var=0;
subsubsubmenu = 0;
subsubmenu = 0;
submenu = 0;
dubak=0;
page=0;
counter = 1;
pushed = 0;
Ready = 0;
digitalWrite(RELAY4, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Automatic Mode");
lcd.setCursor(0, 2);
lcd.print(" Wait ");
delay(4000);
}
if (page == 2)
{
var=1;
while(var==1){
buzzermenuclick();
break;
}
var=0;
subsubsubmenu = 0;
subsubmenu = 0;
submenu = 0;
dubak=0;
page=0;
counter = 0;
pushed = 0;
Ready = 0;
digitalWrite(RELAY4, LOW);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Manuel Mode");
lcd.setCursor(0, 2);
lcd.print(" Wait ");
delay(4000);
}
}
if (subsubsubmenu == 5)
{
if (page == 1)
{
var=1;
while(var==1){
buzzersetup();
break;
}
var=0;
subsubsubmenu = 0;
subsubmenu = 0;
submenu = 0;
dubak=0;
page=0;
counter = 1;
pushed = 0;
Ready = 0;
digitalWrite(RELAY1, HIGH);
delay(1000);
digitalWrite(RELAY1, LOW);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Kapi Aciliyor...");
lcd.setCursor(0, 2);
lcd.print(" Bekleyin ");
delay(4000);
}
if (page == 2)
{
var=1;
while(var==1){
buzzermenuclick();
break;
}
var=0;
subsubsubmenu = 0;
subsubmenu = 0;
submenu = 0;
dubak=0;
page=0;
counter = 0;
pushed = 0;
Ready = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Geri Donuluyor... ");
lcd.setCursor(0, 2);
lcd.print(" Bekleyin ");
delay(2000);
}
}
if (subsubsubmenu == 6)
{
if (page == 1)
{
var=1;
while(var==1){
buzzersetup();
break;
}
var=0;
subsubsubmenu = 0;
subsubmenu = 0;
submenu = 0;
dubak=0;
page=0;
counter = 1;
pushed = 0;
Ready = 0;
digitalWrite(RELAY2, HIGH);
delay(1000);
digitalWrite(RELAY2, LOW);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Kapi Kapaniyor");
lcd.setCursor(0, 2);
lcd.print(" Bekleyin ");
delay(4000);
}
if (page == 2)
{
var=1;
while(var==1){
buzzermenuclick();
break;
}
var=0;
subsubsubmenu = 0;
subsubmenu = 0;
submenu = 0;
dubak=0;
page=0;
counter = 0;
pushed = 0;
Ready = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Geri Donuluyor");
lcd.setCursor(0, 2);
lcd.print(" Bekleyin ");
delay(4000);
}
}
if (subsubsubmenu == 7)
{
if (page == 1)
{
var=1;
while(var==1){
buzzersetup();
break;
}
var=0;
subsubsubmenu = 0;
subsubmenu = 0;
submenu = 0;
dubak=0;
page=0;
counter = 1;
pushed = 0;
Ready = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Kapanma Zamani 2 Saniye");
lcd.setCursor(0, 2);
lcd.print(" Bekleyin ");
digitalWrite(RELAY3, HIGH);
delay(2000);
digitalWrite(RELAY3, LOW);
delay(4000);
}
if (page == 2)
{
var=1;
while(var==1){
buzzersetup();
break;
}
var=0;
subsubsubmenu = 0;
subsubmenu = 0;
submenu = 0;
dubak=0;
page=0;
counter = 0;
pushed = 0;
Ready = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Kapanma Zamani 5 Saniye");
lcd.setCursor(0, 2);
lcd.print(" Bekleyin ");
digitalWrite(RELAY3, HIGH);
delay(5000);
digitalWrite(RELAY3, LOW);
delay(4000);
}
if (page == 3)
{
var=1;
while(var==1){
buzzersetup();
break;
}
var=0;
subsubsubmenu = 0;
subsubmenu = 0;
submenu = 0;
dubak=0;
page=0;
counter = 0;
pushed = 0;
Ready = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Kapanma Zamani 10 Saniye");
lcd.setCursor(0, 2);
lcd.print(" Bekleyin ");
digitalWrite(RELAY3, HIGH);
delay(10000);
digitalWrite(RELAY3, LOW);
delay(4000);
}
if (page == 4)
{
var=1;
while(var==1){
buzzersetup();
break;
}
var=0;
subsubsubmenu = 0;
subsubmenu = 0;
submenu = 0;
dubak=0;
page=0;
counter = 0;
pushed = 0;
Ready = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Kapanma Zamani 20 Saniye");
lcd.setCursor(0, 2);
lcd.print(" Bekleyin ");
digitalWrite(RELAY3, HIGH);
delay(20000);
digitalWrite(RELAY3, LOW);
}
}
if (subsubsubmenu == 8)
{
if (page == 1)
{
var=1;
while(var==1){
buzzersetup();
break;
}
var=0;
subsubsubmenu = 0;
subsubmenu = 0;
submenu = 0;
dubak=0;
page=0;
counter = 1;
pushed = 0;
Ready = 0;
digitalWrite(RELAY4, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Otomatic Mod");
lcd.setCursor(0, 2);
lcd.print(" Bekleyin ");
delay(4000);
}
if (page == 2)
{
var=1;
while(var==1){
buzzermenuclick();
break;
}
var=0;
subsubsubmenu = 0;
subsubmenu = 0;
submenu = 0;
dubak=0;
page=0;
counter = 0;
pushed = 0;
Ready = 0;
digitalWrite(RELAY4, LOW);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Manuel Mod");
lcd.setCursor(0, 2);
lcd.print(" Bekleyin ");
delay(4000);
}
}
//end of submenu 1
//**********************************************************************************************************************************************************************
if (submenu == 0 && Ready == 1)
{
if (page == 1)
{
var=1;
while(var==1){
buzzermenuclick();
break;
}
var=0;
subsubmenu = 1;
counter = 0;
pushed = 1;
delay(500);
}
if (page == 2)
{
var=1;
while(var==1){
buzzermenuclick();
break;
}
var=0;
subsubmenu = 2;
counter = 0;
pushed = 1; delay(500);
}
if (page == 3)
{
var=1;
while(var==1){
buzzermenuclick();
break;
}
var=0;
subsubmenu = 3;
counter = 0;
pushed = 1; delay(500);
}
if (page == 4)
{
var=1;
while(var==1){
buzzermenuclick();
break;
}
var=0;
subsubmenu = 4;
counter = 0;
pushed = 1; delay(500);
}
}//end of submenu 0
if (subsubmenu == 1 && Ready == 1)
{
if (dubak == 1)
{
var=1;
while(var==1){
buzzermenuclick();
break;
}
var=0;
subsubsubmenu = 1;
counter = 0;
pushed = 1;
delay(500);
}
if (dubak == 2)
{
var=1;
while(var==1){
buzzermenuclick();
break;
}
var=0;
subsubsubmenu = 2;
counter = 0;
pushed = 1;
delay(500);
}
if (dubak == 3)
{
var=1;
while(var==1){
buzzermenuclick();
break;
}
var=0;
subsubsubmenu = 3;
counter = 0;
pushed = 1;
delay(500);
}
if (dubak == 4)
{
var=1;
while(var==1){
buzzermenuclick();
break;
}
var=0;
subsubsubmenu = 4;
counter = 0;
pushed = 1;
delay(500);
}
}//end of submenu 0
if (subsubmenu == 2 && Ready == 1)
{
if (dubak == 1)
{
var=1;
while(var==1){
buzzermenuclick();
break;
}
var=0;
subsubsubmenu = 5;
counter = 0;
pushed = 1;
delay(500);
}
if (dubak == 2)
{
var=1;
while(var==1){
buzzermenuclick();
break;
}
var=0;
subsubsubmenu = 6;
counter = 0;
pushed = 1;
delay(500);
}
if (dubak == 3)
{
var=1;
while(var==1){
buzzermenuclick();
break;
}
var=0;
subsubsubmenu = 7;
counter = 0;
pushed = 1;
delay(500);
}
if (dubak == 4)
{
var=1;
while(var==1){
buzzermenuclick();
break;
}
var=0;
subsubsubmenu = 8;
counter = 0;
pushed = 1;
delay(500);
}
}
}
//Add limit for the counter. Each line of the menu has 5 points. Since my menu has 4 lines the maximum counter will be from 0 to 20
//If you add more lines for the menu, increase this value
if (counter > 20)
{
counter = 20;
}
if (counter < 0)
{
counter = 0;
}
}//end void
void buzzersetup() {
digitalWrite(buzzer, HIGH);
delay(10);
digitalWrite(buzzer, LOW);
delay(40);
digitalWrite(buzzer, HIGH);
delay(60);
digitalWrite(buzzer, LOW);
delay(40);
digitalWrite(buzzer, HIGH);
delay(80);
digitalWrite(buzzer, LOW);
delay(40);
digitalWrite(buzzer, HIGH);
delay(120);
digitalWrite(buzzer, LOW);
}
void buzzermenuclick() {
digitalWrite(buzzer, HIGH);
delay(40);
digitalWrite(buzzer, LOW);
delay(120);
digitalWrite(buzzer, HIGH);
delay(80);
digitalWrite(buzzer, LOW);
}
void buzzermenuaction() {
digitalWrite(buzzer, HIGH);
delay(40);
digitalWrite(buzzer, LOW);
}
void openingMusic(){
digitalWrite(buzzer, HIGH);
delay(300);
digitalWrite(buzzer, LOW);
delay(200);
digitalWrite(buzzer, HIGH);
delay(100);
digitalWrite(buzzer, LOW);
delay(200);
digitalWrite(buzzer, HIGH);
delay(600);
digitalWrite(buzzer, LOW);
}
//Interruption vector
ISR(PCINT0_vect) {
clk_State = (PINB & B00000001); //pin 8 state, clock pin?
dt_State = (PINB & B00000010);
if (clk_State != Last_State) {
// If the data state is different to the clock state, that means the encoder is rotating clockwise
if (dt_State == clk_State) {
counter ++;
}
else {
counter --;
}
}
Last_State = clk_State; // Updates the previous state of the data with the current state
}
*******************************************
PLC Imitation Codes:
#include <Servo.h>
Servo servo;
#define trigpin 12
#define echopin 11
#define RELAY1 6
#define RELAY2 5
#define RELAY3 4
#define RELAY4 3
static int openPos = 90;
static int closePos = 180;
static unsigned long closingTime;
static int Time;
static int range;
int i=0;
static unsigned long sec=millis();
void setup() {
pinMode(trigpin, OUTPUT);
pinMode(echopin, INPUT);
pinMode(RELAY1, INPUT);
pinMode(RELAY2, INPUT);
pinMode(RELAY3, INPUT);
pinMode(RELAY4, INPUT);
servo.attach(10);
}
void loop() {
int relay1state = digitalRead(RELAY1);
int relay2state = digitalRead(RELAY2);
int relay3state = digitalRead(RELAY3);
int relay4state = digitalRead(RELAY4);
if(relay3state == 1){
closeTimeCalculator();
}
if(relay4state == 1){
automaticMode();
}
if(relay4state == 0){
if(relay1state == 1){
servo.write(openPos);
}
if(relay2state == 1){
servo.write(closePos);
delay(2000);
}
}
}
void automaticMode(){
digitalWrite(trigpin, HIGH);
delayMicroseconds(1000);
digitalWrite(trigpin, LOW);
Time = pulseIn(echopin, HIGH);
range = (Time/2) / 28.3;
if(range>=0 && range<20){
servo.write(openPos);
delay(closingTime);
servo.write(closePos);
}
}
void closeTimeCalculator(){
if(millis()-sec >=1){
sec=millis();
i++;
}
closingTime=i;
}
Comments