Arduino Ultra Mega Timers

27,273

70

120

Introduction: Arduino Ultra Mega Timers

Hi! "Arduino Timer with on/off setpoint" is my most viewed instructable by far, so i got a lot of questions in the comments, inbox and youtube, about how to add minutes,seconds, days and save settings on the eeprom.... so i decided to bring an old code, made with PIC, to arduino, easier to share and make.

I tried to make this project compact, easy to use and set up, with 3 buttons and a 16x2 lcd.The interface is based on my previous instructable "Turn single screen into multiple screens". If you want to learn how this interface was made, please visit:

https://www.instructables.com/id/Arduino-LCD-16x2-Turn-Single-Screen-Into-Multiple-/

Here you have 6 codes to choose:

All timers are hours,minutes and seconds (on/off) programmables. Save data on the eeprom.

-1Timer for everyday,

-1Timer, selectable day

-4 Timers. 1 relay, for everyday

All timers has a "simple" version, that means, without lcd interface. Useful if you want to save money or don't need to chage the settings periodically.

These timers can recover the data and work even in case of power failure. The code was made to activate the relay at any moment.

We'll start from the basic timer to the more complete one.With this timer you can even turn on something for a second!

You will need:

-Arduino UNO

-LCD 16x2 (I2C)

-RTC 3231 module

-Push buttons x3

-10K resistors x3

-Relay module x1

-Breadboard,wires,etc

Watch the video!

Step 1: First Steps

First of all, we need to set up the LCD,RTC and clear the arduinos eeprom.

-LCD The lcd must have an address, declared at the beginning of the code:

LiquidCrystal_I2C lcd(0x3F,16,2);//0x3F is my lcd address, maybe not yours!

If you don't know your address, use the utility "I2C scanner" . Connect your lcd as follows:

-VCC to arduino 5V

-GND to arduino GND

-SDA to arduino analog pin 4

-SCL to arduino analog pin 5

Upload the code and open the serial monitor, the address will be displayed. Replace the address if it's not the same (0x3F) in the codes of the next steps.

Download:

https://gist.github.com/tfeldmann/5411375

-RTC We'll use the RTC 3231, but the rigth time must be programmed. Add the RTClib-master to your Arduino library. Go to File/examples/RTClib/ds3231 .Upload the code. This sketch take the Date and Time according the computer you're using (right when you compile the code) and uses that to program the RTC. If your computer time is not set right you should fix that first. Then you must press the Upload button to compile and then immediately upload.

Warning !:If you compile and then upload later, the clock will be off by that amount of time. Then open up the Serial monitor window to show that the time has been set.

Connect your rtc as follows:

-VCC to arduino 5V
-GND to arduino GND

-SDA to arduino analog pin 4

-SCL to arduino analog pin 5

If you don't know, the lcd and the rtc can be connected at the same time to the I2C bus (analog 4 SDA, analog 5 SCL).

-EEPROM clear Commonly ,eeprom values are 255 x address and we need to set these values to 0. The eeprom library is already included on your arduino IDE.

Go to File/Examples/EEPROM/eeprom_clear.

Upload the code and wait for the pin 13 led to turn on. You can check your values with the eeprom_read code.

Watch the video!

The RTC and LCD libraries used in this tutorial:

Step 2: Timer's Trick

One of the challenges here is to compare the "on time" and "off time" with the current time at every moment. One can think in something like this:

if(now hour==on hour &&now minute==on minute && now second==on second)

relay on

if(now hour==off hour&&now minute==off minute&&now second==off second)

relay off

This might work, but what if your on setpoint is 12:30:00, your off setpoint 15:45:15 and the current time is 13:00:00 ? Well, you will wait until the next day to turn on your device ! Or what if you lose power beetwen 12:30:00 and 15:45:15? The same thing:to wait for the settings to be triggered.

If you looked at my previous timer, there are a lot of if/else statements to control the relay, because time is cyclic and we need to cover all the possible scenarios. But to add minutes and seconds it´s something else. All values can be higher or lower than the on/off settings or current time and try to compare it will be a mess.

So i thought in something like military time or string number from 0 to 235959, and that's the trick of these timers. So, we convert the current time, on setpoint and off setpoint into single number.

I just will explain how the timers work,because the interface to change settings and display values,etc, can be studied in my instructable of multiple screens. Link in the intro.

First, we create the variables for the timer (on/off):

//------First Timer
byte onhour1;

byte onmin1;

byte onsec1;

byte offhour1;

byte offmin1;

byte offsec1;

A byte data type (0 to 255 unsigned) was used to store the values. A byte can be easily stored on the eeprom (1 data x address) and the bigger number will be 59 (minute or second). We take the values from the eeprom, 0 at the very beginning, because the eeprom was cleared.Where ( ) is the eeprom address.

void setup.......

//--------eePROM read values-------//
//------First Timer

onhour1=EEPROM.read(0);

onmin1=EEPROM.read(1);

onsec1=EEPROM.read(2);

offhour1=EEPROM.read(3);

offmin1=EEPROM.read(4);

offsec1=EEPROM.read(5);

These values can be changed and saved, later on with the buttons interface.

But we can't do the maths (conversion to single number) with bytes because our bigger number will be 235,959 or int =32,767 (positive) or unsigned int=65,535. So, unsigned long will be.

We create another variable to convert byte into unsigned long. Also, the final values to work with: on_Time1 and off_Time1

//------To convert first timer into Single number
unsigned long on_Time1;

unsigned long on_hour1;

unsigned long on_min1;

unsigned long on_sec1;

unsigned long off_Time1;

unsigned long off_hour1;

unsigned long off_min1;

unsigned long off_sec1;

//-------To convert clock into single number
unsigned long Time;

unsigned long Hour;

unsigned long Min;

unsigned long Sec;

The conversion is executed in the void loop. For the current time, we take the values from the rtc with the library function now() ,hour, minute, second and assign this values to Hour,Min and Sec. "Time" is the result of the sum of Hour*10000 ; Min*100 and Sec.

Example: 15:45:34 = (15*10000 + 45*100 + 34) = 154,534

//-------------Conversion----------//

//---------Converting clock time into single number

Hour = now.hour();

Min = now.minute();

Sec = now.second();

Time = (Hour*10000+ Min*100 +Sec*1);

And the same with the on/off settings. Here we take the values from the beginning (byte) and assign these values as follows:

//--------Converting firt timer on/off into single number

on_hour1=onhour1;

on_min1=onmin1;

on_sec1=onsec1;

on_Time1=(on_hour1*10000 + on_min1*100 + on_sec1);

off_hour1=offhour1;

off_min1=offmin1;

off_sec1=offsec1;

off_Time1=(off_hour1*10000 + off_min1*100 + off_sec1);

The final result are the 3 variables with we will work : Time, on_Time1 and off_Time1

Now the relay function. Here we compare "Time" with "on_Time1" and "off_Time1" to turn on or off the relay. We have 3 main "if" statements:

1)if(onhour1 == offhour1 && onmin1==offmin1 && onsec1==offsec1){

digitalWrite(Relay, LOW); }

This statement is an enable/disable function. We use the byte values, because we don't need any conversion here. If all values are the same the relay is off. If you change , even a second, the timer will work.

2)if(on_Time1 < off_Time1){

if(Time >= on_Time1 && Time < off_Time1){ //Start

digitalWrite(Relay, HIGH);

}

else if(Time >= off_Time1) {

digitalWrite(Relay, LOW);

}

else{

digitalWrite(Relay, LOW);

}

}

3)if (on_Time1 > off_Time1){

if(Time >= on_Time1 && Time <= 235959){ //Start

digitalWrite(Relay, HIGH);

}

else if(Time < off_Time1 ){

digitalWrite(Relay, HIGH);

}

else if(Time >= off_Time1 && Time < on_Time1){

digitalWrite(Relay, LOW); } }

These 2 functions cover the 2 possible settings: "on time" lower than "off time" and "on time" higher than "off time".Inside each one you can find 3 statements more to control the relay at any moment.The functions can be easily understand with a graphic demo. Watch the pictures!

With the buttons interface we can change the values (on/off) and store our new ones.This is the structure to store the values. As i have said, we store the byte values on a single address. where:

(address, byte value)

EEPROM.write(0, onhour1);
EEPROM.write(1, onmin1);

EEPROM.write(2, onsec1);

EEPROM.write(3, offhour1);

EEPROM.write(4, offmin1);

EEPROM.write(5, offsec1);

Step 3: 1 Timer for Everyday

This timer is the base for the next ones. Mount the circuit following the schematic, remember RTC and LCD share the same pins (analog 4 SDA ; analog 5 SCL).

Upload the code, remember to add the libraries RTClib and LiquidCrystal_I2C.

You have 3 buttons to move the 3 main pages with the up/down buttons and select button to enter and move the submenus.

The first page shows you a message and the current time.

The second page is the on/off interface, here you can change the setpoints. Press the select button to enter to submenu, an arrow will be placed in front of each item, press up or down to set the on hour, minute, second and off hour, minute, second. Press the select button to move beetwen items (forward only) The final item is the "back" char, if you press up, it will exit the submenu and now you can move the main pages. If you press down, the arrow will be placed in front of the first item.

The third page is to save your settings. Just press the select buton and all your data will be stored on the eeprom. A message "SAVED!" will be displayed and automatically redirect to the main page.

This timer will work everyday and in case of power failure or disconnection will recover the data from the eeprom to start again.

With the relay you can control your devices. The relay is activated with a high signal (5V).

Warning! Be careful with the maximum load of the relay!

Step 4: 1 Timer, Selectable Day

This timer is for those who want to control the day where the timer is activated. For this, we'll use the RTC's function "now.dayOfTheWeek()" and it values can be 1 to 7 ; Monday to Sunday. To assign the day of the week to each number, we use this(global variables):

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

To display it on the LCD (main page):

lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);

We need new variables to know if the day is enebled/disabled.So:

//------Days of the week
boolean Sun1;

boolean Mon1;

boolean Tue1;

boolean Wed1;

boolean Thu1;

boolean Fri1;

boolean Sat1;

We use boolean values (1 or 0) and as the other variables, we take the values from the eeprom.Boolean can be stored in 1 address. The last address used was 5 (offsec1), so we continue with:

void setup.....

Sun1=EEPROM.read(6);
Mon1=EEPROM.read(7);

Tue1=EEPROM.read(8);

Wed1=EEPROM.read(9);

Thu1=EEPROM.read(10);

Fri1=EEPROM.read(11);

Sat1=EEPROM.read(12);

Remember, your first value will be 0 (eeprom clear). So 0 is for disable and 1 for enable day.

In order to control the relay, we need to check the current day and check if the timer is enabled/disabled for that day.

Another switch function is used, where every "case" will be the value of "now.dayOfTheWeek()" (1 to 7)

//----Relay Function per day----//
switch(now.dayOfTheWeek()){ //now.dayOfTheWeek values 1 to 7, monday to sunday

case 1: //If monday

if(Mon1==1){

First_Timer();

}

else{

digitalWrite(Relay1, LOW);

}

break;

case 2: //If tuesday

if(Tue1==1){

First_Timer();

}

else{

digitalWrite(Relay1, LOW);

} break;

case 3: .......and so on...

For example: If today is monday (now.dayOfTheWeek() =1), we enter to the first case. if the boolean value Mon1==1 (day enabled), we call a custom function "First_Timer()", the same relay function from the previous timer, now working as a custom function, so we don't need to write it on every case. If we put a 0 the relay function will be LOW (day disabled). So we use one case per day and skip the others.

Now we need to add another screen to the interface to change the settings.

The main page shows you the current day and time.

The second page the on/off setings.

Here we introduce the new page where you can select the day to activate the relay and it works the same as the others: the arrow indicates the item, if you press the up button you will put a 1 on that day and it will be enabled. If you press down, you will put a 0 and the day will be disabled.

The fourth page save the settings, on/off time and day enabled/disabled. The structure to save:

EEPROM.write(0, onhour1);
EEPROM.write(1, onmin1);

EEPROM.write(2, onsec1);

EEPROM.write(3, offhour1);

EEPROM.write(4, offmin1);

EEPROM.write(5, offsec1);

EEPROM.write(6, Sun1);

EEPROM.write(7, Mon1);

EEPROM.write(8, Tue1);

EEPROM.write(9, Wed1);

EEPROM.write(10, Thu1);

EEPROM.write(11, Fri1);

EEPROM.write(12, Sat1);

Step 5: 4 Timers 1 Relay for Everyday

Another request from the users. This timer is able to control 4 event at day with a single output. No much to say about this because we only add more variables for the timer 2, 3, and 4, also the interface to move the settings. We continue reading and writting from the eeprom, from the last address used.

Note: Be careful to don't overlap the timers, because any of it can turn on or off the relay.

So, here you have 3 timers with a nice interface. For the "simple" version, you just need to change the values within "///////////".Default values are 0.

on/offhour1, 2,3,4 = 0-23

on/offmin1, 2,3,4 =0-59

on/offsec1, 2,3,4 =0-59

Day enabled/disabled =1 for enable 0 for disable.

"Simple" timers doesn't need eeprom save because you have already stored the values. This useful too, if you want to study the timer's code.

As you can see, more timers can be added, following the logic,and you can use the "selectable day" function on it.

If you are a beginner, this project it's easy to make and run, but if you want to go deep into the code, that's another story. This is not rocket science, but you need some knowledge to face the codes. That's why i've separeted the codes for better understanding. i'm just saying this because i get a lot of question from users about how to modify codes and i can't do that for you, I can always help you, of course.I hope you understand.

Microcontroller Contest

Participated in the
Microcontroller Contest

6 People Made This Project!

Recommendations

  • Make it Glow Contest

    Make it Glow Contest
  • First Time Author Contest

    First Time Author Contest
  • PCB Challenge

    PCB Challenge

120 Discussions

0
cryoterror
cryoterror

2 months ago

Hy, first of all you did a great job. I made this project too, and i am using it to light a fish tank. In this project i am using a 20x4 LCD and i am wondering if i can (how to) show on the LCD the temperature information from the ds3231 module as external temperature and from another sensor like LM35 (or better) the temperature of water. Thank you very much and excuse my english.

20201027_103936.jpg
0
NicolasJ7
NicolasJ7

Reply 2 months ago

Hi! I've never used the ds3231 temp sensor, but you can find info on forums and sites for sure. I recommend the ds18b20 temp sensor to sense water temp. Take a look at my projects where I teach how to use it.

0
zaratool61
zaratool61

Question 3 months ago

in this code block; After the first condition is satisfied, the second condition setpoint is being ignored. what would be the reason?

switch(now.dayOfTheWeek()) //now.dayOfTheWeek values 1 to 7, monday to sunday
{
case 1: //If monday
if(Mon1==1)
{
First_Timer();
}
else if(Mon2==1)
{
Second_Timer();
}
else if(Mon3==1)
{
Third_Timer();
}
else if(Mon4==1)
{
Fourth_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 2: //If tuesday
if(Tue1==1)
{
First_Timer();
}
else if(Tue2==1)
{
Second_Timer();
}
else if(Tue3==1)
{
Third_Timer();
}
else if(Tue1==1)
{
Fourth_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 3: //If wednesday
if(Wed1==1)
{
First_Timer();
}
else if(Wed2==1)
{
Second_Timer();
}
else if(Wed3==1)
{
Third_Timer();
}
else if(Wed4==1)
{
Fourth_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 4: //If thursday
if(Thu1==1)
{
First_Timer();
}
else if(Thu2==1)
{
Second_Timer();
}
else if(Thu3==1)
{
Third_Timer();
}
else if(Thu4==1)
{
Fourth_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
/////////////////////////////
case 5: //If friday
if(Fri1==1)
{
First_Timer();
}
else if(Fri2==1)
{
Second_Timer();
}
else if(Fri3==1)
{
Third_Timer();
}
else if(Fri4==1)
{
Fourth_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 6: //If saturday
if(Sat1==1)
{
First_Timer();
}
else if(Sat2==1)
{
Second_Timer();
}
else if(Sat3==1)
{
Third_Timer();
}
else if(Sat4==1)
{
Fourth_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 7: //If sunday
if(Sun1==1)
{
First_Timer();
}
else if(Sun2==1)
{
Second_Timer();
}
else if(Sun3==1)
{
Third_Timer();
}
else if(Sun4==1)
{
Fourth_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
}
//////////////////////////////////////////////////////////////////////////////////////
//switch day
}//void loop
////////////////////////////////////////////////////////////////////////////////////////////
void First_Timer() //Custom function to check timer
{
if(onhour1 == offhour1 && onmin1==offmin1 )
{
digitalWrite(Relay1, LOW);
}
if(on_Time1 < off_Time1)
{
if(Time >= on_Time1 && Time < off_Time1) //Start
{
digitalWrite(Relay1, HIGH);
}
else if(Time >= off_Time1)
{
digitalWrite(Relay1, LOW);
}
else{
digitalWrite(Relay1, LOW);
}
}
if (on_Time1 > off_Time1)
{
if(Time >= on_Time1 && Time <= 235959 )//Start
{
digitalWrite(Relay1, HIGH);
}
else if(Time < off_Time1)
{
digitalWrite(Relay1, HIGH);
}
else if(Time >= off_Time1 && Time < on_Time1)
{
digitalWrite(Relay1, LOW);
}
}
}//First timer
//////////////////////////////////////////////////////////////////////////////////////////////////////
void Second_Timer() //Custom function to check timer
{
if(onhour2 == offhour2 && onmin2==offmin2)
{
digitalWrite(Relay1, LOW);
}
if(on_Time2 < off_Time2 )
{
if(Time >= on_Time2 && Time < off_Time2) //Start
{
digitalWrite(Relay1, HIGH);
}
else if(Time >= off_Time2)
{
digitalWrite(Relay1, LOW);
}
else
{
digitalWrite(Relay1, LOW);
}
}
if (on_Time2 > off_Time2)
{
if(Time >= on_Time2 && Time <= 235959 )//Start
{
digitalWrite(Relay1, HIGH);
}
else if(Time < off_Time2 )
{
digitalWrite(Relay1, HIGH);
}
else if(Time >= off_Time2 && Time < on_Time2)
{
digitalWrite(Relay1, LOW);
}
}
} //Second Timer
//////////////////////////////////////////////////////////////////////////////////////////////////////
void Third_Timer() //Custom function to check timer
{
if(onhour3 == offhour3 && onmin3==offmin3 )
{
digitalWrite(Relay1, LOW);
}
if(on_Time3 < off_Time3 )
{
if(Time >= on_Time3 && Time < off_Time3 ) //Start
{
digitalWrite(Relay1, HIGH);
}
else if(Time >= off_Time3 )
{
digitalWrite(Relay1, LOW);
}
else{
digitalWrite(Relay1, LOW);
}
}
if (on_Time3 > off_Time3)
{
if(Time >= on_Time3 && Time <= 235959 ) //Start
{
digitalWrite(Relay1, HIGH);
}
else if(Time < off_Time3 )
{
digitalWrite(Relay1, HIGH);
}
else if(Time >= off_Time3 && Time < on_Time3)
{
digitalWrite(Relay1, LOW);
}
}
} // Third Timer
//////////////////////////////////////////////////////////////////////////////////////////////////////
void Fourth_Timer() //Custom function to check timer
{
if(onhour4 == offhour4 && onmin4==offmin4)
{
digitalWrite(Relay1, LOW);
}
if(on_Time4 < off_Time4 )
{
if(Time >= on_Time4 && Time < off_Time4)//Start
{
digitalWrite(Relay1, HIGH);
}
else if(Time >= off_Time4)
{
digitalWrite(Relay1, LOW);
}
else
{
digitalWrite(Relay1, LOW);
}
}
if (on_Time4 > off_Time4 )
{
if(Time >= on_Time4 && Time <= 235959 )//Start
{
digitalWrite(Relay1, HIGH);
}
else if(Time < off_Time4)
{
digitalWrite(Relay1, HIGH);
}
else if(Time >= off_Time4 && Time < on_Time4)
{
digitalWrite(Relay1, LOW);
}
}
} //Fourth Timer
/////////////////////////////////////////////////////////////////////////////////////////

0
zaratool61
zaratool61

Question 3 months ago

I solved the case, the case should be up to 7, but how should I organize the code accordingly. is there a different way.

0
zaratool61
zaratool61

Question 3 months ago

This code is being compiled, but not running.

//Thank you Nicolas Jarpa wholeheartedly.
//Multiple Timer RTC3231+LCD+Single Relay+Select day+eeprom
#include <EEPROM.h>
#include <RTClib.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20,2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);//0x3F is my lcd address, maybe not yours!
RTC_DS3231 rtc;
char daysOfTheWeek[7][12] = {"Paz", "Pzt", "Sal", "Car", "Per", "Cum", "Cmt"};
//-----------------------//
//------Variables--------//
//-----------------------//
//------First Timer
byte onhour1;
byte onmin1;
byte offhour1;
byte offmin1;
//-----Second Timer
byte onhour2;
byte onmin2;
byte offhour2;
byte offmin2;
//-----Third Timer
byte onhour3;
byte onmin3;
byte offhour3;
byte offmin3;
//-----Fourth Timer
byte onhour4;
byte onmin4;
byte offhour4;
byte offmin4;
//------Days of the week
boolean Sun1;
boolean Mon1;
boolean Tue1;
boolean Wed1;
boolean Thu1;
boolean Fri1;
boolean Sat1;
boolean Sun2;
boolean Mon2;
boolean Tue2;
boolean Wed2;
boolean Thu2;
boolean Fri2;
boolean Sat2;
boolean Sun3;
boolean Mon3;
boolean Tue3;
boolean Wed3;
boolean Thu3;
boolean Fri3;
boolean Sat3;
boolean Sun4;
boolean Mon4;
boolean Tue4;
boolean Wed4;
boolean Thu4;
boolean Fri4;
boolean Sat4;
//------Pages or menus
int page_counter=1;
int subpage1_counter=0;
int subpage2_counter=0;
int subpage3_counter=0;
int subpage4_counter=0;
int subpage5_counter=0;
//-------To convert clock into single number
unsigned long Time;
unsigned long Hour;
unsigned long Min;
//------To convert first timer into Single number
unsigned long on_Time1;
unsigned long on_hour1;
unsigned long on_min1;
unsigned long off_Time1;
unsigned long off_hour1;
unsigned long off_min1;
//------To convert second timer into Single number
unsigned long on_Time2;
unsigned long on_hour2;
unsigned long on_min2;
unsigned long off_Time2;
unsigned long off_hour2;
unsigned long off_min2;
//------To convert Third timer into Single number
unsigned long on_Time3;
unsigned long on_hour3;
unsigned long on_min3;
unsigned long off_Time3;
unsigned long off_hour3;
unsigned long off_min3;
//------To convert Fourth timer into Single number
unsigned long on_Time4;
unsigned long on_hour4;
unsigned long on_min4;
unsigned long off_Time4;
unsigned long off_hour4;
unsigned long off_min4;
//-------Push buttons current/last state
boolean current_up = LOW;
boolean last_up=LOW;
boolean current_sel = LOW;
boolean last_sel = LOW;
boolean last_down = LOW;
boolean current_down = LOW;
//-------Pins
byte Relay1 =13;//Relay to pin 13
int up=2; //Up button to pin 2
int sel=3; //Select button to pin 3
int down=4; //Down button to pin 4
char t[32];
//Custom return char
byte back[8] = {
0b00100,
0b01000,
0b11111,
0b01001,
0b00101,
0b00001,
0b00001,
0b11111
};
//Custom arrow char
byte arrow[8] = {
0b01000,
0b00100,
0b00010,
0b11111,
0b00010,
0b00100,
0b01000,
0b00000
};
void setup() {
pinMode(Relay1, OUTPUT);
Wire.begin();
rtc.begin();
lcd.begin(20,4);
lcd.backlight();
lcd.clear();
lcd.createChar(1, back);//Custom chars
lcd.createChar(2, arrow);
rtc.adjust(DateTime(2020, 9, 30, 0, 0, 0));
//--------eePROM read values-------//
//------First Timer
onhour1=EEPROM.read(0);
onmin1=EEPROM.read(1);
offhour1=EEPROM.read(2);
offmin1=EEPROM.read(3);
//------Second Timer
onhour2=EEPROM.read(4);
onmin2=EEPROM.read(5);
offhour2=EEPROM.read(6);
offmin2=EEPROM.read(7);
//------Third Timer
onhour3=EEPROM.read(8);
onmin3=EEPROM.read(9);
offhour3=EEPROM.read(10);
offmin3=EEPROM.read(11);
//------Fourth Timer
onhour4=EEPROM.read(12);
onmin4=EEPROM.read(13);
offhour4=EEPROM.read(14);
offmin4=EEPROM.read(15);
//-----Week Timer
Sun1=EEPROM.read(16);
Mon1=EEPROM.read(17);
Tue1=EEPROM.read(18);
Wed1=EEPROM.read(19);
Thu1=EEPROM.read(20);
Fri1=EEPROM.read(21);
Sat1=EEPROM.read(22);
Sun2=EEPROM.read(23);
Mon2=EEPROM.read(24);
Tue2=EEPROM.read(25);
Wed2=EEPROM.read(26);
Thu2=EEPROM.read(27);
Fri2=EEPROM.read(28);
Sat2=EEPROM.read(29);
Sun3=EEPROM.read(30);
Mon3=EEPROM.read(31);
Tue3=EEPROM.read(32);
Wed3=EEPROM.read(33);
Thu3=EEPROM.read(34);
Fri3=EEPROM.read(35);
Sat3=EEPROM.read(36);
Sun4=EEPROM.read(37);
Mon4=EEPROM.read(38);
Tue4=EEPROM.read(39);
Wed4=EEPROM.read(40);
Thu4=EEPROM.read(41);
Fri4=EEPROM.read(42);
Sat4=EEPROM.read(43);
}
//---- De-bouncing function for all buttons----//
boolean debounce(boolean last, int pin)
{
boolean current = digitalRead(pin);
if (last != current)
{
delay(10);
current = digitalRead(pin);
}
return current;
}
void loop()
{
current_up = debounce(last_up, up); //Debounce for Up button
current_sel = debounce(last_sel, sel); //Debounce for Select button
current_down = debounce(last_down, down); //Debounce for Down button
DateTime now = rtc.now(); // Clock call
now = rtc.now();
sprintf(t, "%02d:%02d:%02d %02d/%02d/%02d", now.hour(), now.minute(), now.second(), now.day(), now.month(), now.year());
//-----Up/Down functions to move main pages------///
if(subpage1_counter==0 && subpage2_counter==0 && subpage3_counter==0 && subpage4_counter==0 && subpage5_counter==0)//up/down buttons enabled if subpages counters are 0,Disabled if 1,2..etc to work on submenus
{
//Page Up
if (last_up== LOW && current_up == HIGH) //Up button pressed
{
lcd.clear(); //Clear lcd if page is changed to print new one
if(page_counter <7) //Page counter never higher than 4(total of pages)
{
page_counter ++; //Page up
}
else
{
page_counter= 1; //If higher than 4 (last page)go to main page
}
}
last_up = current_up; //Save up button last state
//Page Down
if (last_down== LOW && current_down == HIGH) //Down button pressed
{
lcd.clear(); //Clear lcd if page is changed to print new one
if(page_counter >1) //Page counter never lower than 1
{
page_counter --; //Page down
}
else
{
page_counter= 7; //If lower than 1(first page)go to last page
}
}
last_down = current_down; //Save down button last state
}
//------------Pages and submenus display and control----------//
switch (page_counter)
{
case 1: //Content of main page
last_sel=current_sel; //Save last state of select button when we jump from the save screen
lcd.setCursor(0,1);
lcd.print("TARIH:");
lcd.setCursor(0,0);
lcd.print("SAAT:");
lcd.setCursor(0,2);
lcd.print("T1:");
lcd.setCursor(12,2);
lcd.print("T2:");
lcd.setCursor(0,3);
lcd.print("T3:");
lcd.setCursor(12,3);
lcd.print("T4:");
lcd.setCursor(8,2);
lcd.print("-R1-");
lcd.setCursor(8,3);
lcd.print("-R2-");
//--------Show Time On LCD
lcd.setCursor(6,0);
if(now.hour() < 10)
{
lcd.print("0");
}
lcd.print(now.hour(), DEC); //Print hour
lcd.print(':');
if(now.minute() < 10)
{
lcd.print("0");
}
lcd.print(now.minute(), DEC); //Print min
lcd.print(':');
if(now.second() < 10)
{
lcd.print("0");
}
lcd.print(now.second(), DEC); //Print sec
lcd.setCursor(6,1);
if(now.day() < 10)
{
lcd.print("0");
}
lcd.print(now.day(), DEC); //Print hour
lcd.print('/');
if(now.month() < 10)
{
lcd.print("0");
}
lcd.print(now.month(), DEC); //Print min
lcd.print('/');
if(now.year() < 10)
{
lcd.print("0");
}
lcd.print(now.year(), DEC); //Print sec
lcd.setCursor(17,1);
lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
lcd.setCursor(3,2);
if(onhour1<10)
{
lcd.print("0");
}
lcd.print(onhour1);
lcd.setCursor(6,2);
if(onmin1<10)
{
lcd.print("0");
}
lcd.print(onmin1);
lcd.setCursor(15,2);
if(onhour2<10)
{
lcd.print("0");
}
lcd.print(onhour2);
lcd.setCursor(18,2);
if(onmin2<10)
{
lcd.print("0");
}
lcd.print(onmin2);
lcd.setCursor(3,3);
if(onhour3<10)
{
lcd.print("0");
}
lcd.print(onhour3);
lcd.setCursor(6,3);
if(onmin3<10)
{
lcd.print("0");
}
lcd.print(onmin3);
lcd.setCursor(15,3);
if(onhour4<10){
lcd.print("0");
}
lcd.print(onhour4);
lcd.setCursor(18,3);
if(onmin4<10)
{
lcd.print("0");
}
lcd.print(onmin4);
break;
case 2: //Content and functions of page 2
lcd.setCursor(0,0);
lcd.print("T1:");
lcd.setCursor(5,0);
lcd.write(byte(1));
lcd.setCursor(0,1);
lcd.print("T2:");
lcd.setCursor(5,1);
lcd.write(byte(1));
lcd.setCursor(0,2);
lcd.print("T3:");
lcd.setCursor(5,2);
lcd.write(byte(1));
lcd.setCursor(0,3);
lcd.print("T4:");
lcd.setCursor(5,3);
lcd.write(byte(1));
lcd.setCursor(7,0); //Printing on/off values
if(onhour1<10)
{
lcd.print("0");
}
lcd.print(onhour1);
lcd.setCursor(10,0);
if(onmin1<10)
{
lcd.print("0");
}
lcd.print(onmin1);
lcd.setCursor(13,0);
if(offhour1<10)
{
lcd.print("0");
}
lcd.print(offhour1);
lcd.setCursor(16,0);
if(offmin1<10)
{
lcd.print("0");
}
lcd.print(offmin1);
lcd.setCursor(7,1); //Printing on/off values
if(onhour2<10)
{
lcd.print("0");
}
lcd.print(onhour2);
lcd.setCursor(10,1);
if(onmin2<10)
{
lcd.print("0");
}
lcd.print(onmin2);
lcd.setCursor(13,1);
if(offhour2<10)
{
lcd.print("0");
}
lcd.print(offhour2);
lcd.setCursor(16,1);
if(offmin2<10)
{
lcd.print("0");
}
lcd.print(offmin2);
lcd.setCursor(7,2); //Printing on/off values
if(onhour3<10)
{
lcd.print("0");
}
lcd.print(onhour3);
lcd.setCursor(10,2);
if(onmin3<10)
{
lcd.print("0");
}
lcd.print(onmin3);
lcd.setCursor(13,2);
if(offhour3<10)
{
lcd.print("0");
}
lcd.print(offhour3);
lcd.setCursor(16,2);
if(offmin3<10)
{
lcd.print("0");
}
lcd.print(offmin3);
lcd.setCursor(7,3); //Printing on/off values
if(onhour4<10)
{
lcd.print("0");
}
lcd.print(onhour4);
lcd.setCursor(10,3);
if(onmin4<10)
{
lcd.print("0");
}
lcd.print(onmin4);
lcd.setCursor(13,3);
if(offhour4<10)
{
lcd.print("0");
}
lcd.print(offhour4);
lcd.setCursor(16,3);
if(offmin4<10)
{
lcd.print("0");
}
lcd.print(offmin4);
//--------------Modifying on/off values-------//
// Sub counter control
if (last_sel== LOW && current_sel == HIGH) //select button pressed
{
if(subpage1_counter <17) // subpage counter never higher than 7 (total of items)
{
subpage1_counter ++; //subcounter to move beetwen submenu
}
else
{ //If subpage higher than 7 (total of items) return to first item
subpage1_counter=1;
}
}
last_sel=current_sel; //Save last state of select button
//First item control(subpage_counter =1) onhour1
if(subpage1_counter==1)
{
lcd.setCursor(19,0); //Delete last arrow position (back)
lcd.print(" ");
lcd.setCursor(6,0); //Place arrow in front of selected item
lcd.write(byte(2));
//Move item + or -
if (last_up== LOW && current_up == HIGH)//Up
{
if(onhour1 < 23)
{
onhour1 ++;
}
else{
onhour1 =0;
}
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH)//Down
{
if(onhour1 >0)
{
onhour1 --;
}
else
{
onhour1=23;
}
}
last_down=current_down;
}//subpage1_counter 1
///////////////////////////////////////////////////////////////////////////////////////////////////////
//Second item control(subpage_counter =2) onmin1
if(subpage1_counter==2)
{
lcd.setCursor(6,0); //Delete last arrow position (onhour1)
lcd.print(" ");
lcd.setCursor(9,0); //Place arrow in front of selected item
lcd.write(byte(2));
//Move item + or -
if (last_up== LOW && current_up == HIGH) //Up
{
if(onmin1 < 59)
{
onmin1 ++;
}
else
{
onmin1 =0;
}
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH)//Down
{
if(onmin1 >0)
{
onmin1 --;
}
else
{
onmin1=59;
}
}
last_down=current_down;
}//subpage1_counter 2
//////////////////////////////////////////////////////////////////////////////////////////////////////
//Thirth item control(subpage_counter =3) onsec1
if(subpage1_counter==3)
{
lcd.setCursor(9,0); //Delete last arrow position (onmin1)
lcd.print(" ");
lcd.setCursor(12,0); //Place arrow in front of selected item
lcd.write(byte(2));
//Move item + or -
if (last_up== LOW && current_up == HIGH) //Up
{
if(offhour1 < 23)
{
offhour1++;
}
else
{
offhour1 =0;
}
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH)//Down
{
if(offhour1 >0)
{
offhour1--;
}
else
{
offhour1=23;
}
}
last_down=current_down;
}//subpage1_counter 3
///////////////////////////////////////////////////////////////////////////////////////////////////////
//fourth item control(subpage_counter =4) offhour1
if(subpage1_counter==4)
{
lcd.setCursor(12,0); //Delete last arrow position (onsec1)
lcd.print(" ");
lcd.setCursor(15,0); //Place arrow in front of selected item
lcd.write(byte(2));
//Move item + or -
if (last_up== LOW && current_up == HIGH)//Up
{
if(offmin1 < 59)
{
offmin1++;
}
else
{
offmin1 =0;
}
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH)//Down
{
if(offmin1 >0)
{
offmin1--;
}
else
{
offmin1=59;
}
}
last_down=current_down;
}//subpage1_counter 4
//////////////////////////////////////////////////////////////////////////////////////////////////////
if(subpage1_counter==5)
{
lcd.setCursor(15,0); //Delete last arrow position (back)
lcd.print(" ");
lcd.setCursor(6,1); //Place arrow in front of selected item
lcd.write(byte(2));
//Move item + or -
if (last_up== LOW && current_up == HIGH){ //Up
if(onhour2 < 23)
{
onhour2 ++;
}
else
{
onhour2 =0;
}
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH)//Down
{
if(onhour1 >0)
{
onhour2 --;
}
else
{
onhour2=23;
}
}
last_down=current_down;
}//subpage1_counter 5
///////////////////////////////////////////////////////////////////////////////////////////////////////
//Second item control(subpage_counter =2) onmin1
if(subpage1_counter==6)
{
lcd.setCursor(6,1); //Delete last arrow position (onhour1)
lcd.print(" ");
lcd.setCursor(9,1); //Place arrow in front of selected item
lcd.write(byte(2));
//Move item + or -
if (last_up== LOW && current_up == HIGH) //Up
{
if(onmin2 < 59)
{
onmin2 ++;
}
else
{
onmin2 =0;
}
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH)//Down
{
if(onmin2 >0)
{
onmin2 --;
}
else{
onmin2=59;
}
}
last_down=current_down;
}//subpage1_counter 6
//////////////////////////////////////////////////////////////////////////////////////////////////////
//Thirth item control(subpage_counter =3) onsec1
if(subpage1_counter==7)
{
lcd.setCursor(9,1); //Delete last arrow position (onmin1)
lcd.print(" ");
lcd.setCursor(12,1); //Place arrow in front of selected item
lcd.write(byte(2));
//Move item + or -
if (last_up== LOW && current_up == HIGH)//Up
{
if(offhour2 < 23)
{
offhour2++;
}
else{
offhour2 =0;
}
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH)//Down
{
if(offhour2 >0)
{
offhour2--;
}
else
{
offhour2=23;
}
}
last_down=current_down;
}//subpage1_counter 7
///////////////////////////////////////////////////////////////////////////////////////////////////////
//fourth item control(subpage_counter =4) offhour1
if(subpage1_counter==8)
{
lcd.setCursor(12,1); //Delete last arrow position (onsec1)
lcd.print(" ");
lcd.setCursor(15,1); //Place arrow in front of selected item
lcd.write(byte(2));
//Move item + or -
if (last_up== LOW && current_up == HIGH){ //Up
if(offmin2 < 59){
offmin2++;
}
else{
offmin2 =0;
}
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
if(offmin2 >0){
offmin2--;
}
else{
offmin2=59;
}
}
last_down=current_down;
}//subpage1_counter 8
//////////////////////////////////////////////////////////////////////////////////////////////////
if(subpage1_counter==9)
{
lcd.setCursor(15,1); //Delete last arrow position (back)
lcd.print(" ");
lcd.setCursor(6,2); //Place arrow in front of selected item
lcd.write(byte(2));
//Move item + or -
if (last_up== LOW && current_up == HIGH){ //Up
if(onhour3 < 23){
onhour3 ++;
}
else{
onhour3 =0;
}
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
if(onhour3 >0){
onhour3 --;
}
else{
onhour3=23;
}
}
last_down=current_down;
}//subpage1_counter 9
/////////////////////////////////////////////////////////////////////////////////////////////////////
if(subpage1_counter==10)
{
lcd.setCursor(6,2); //Delete last arrow position (onhour1)
lcd.print(" ");
lcd.setCursor(9,2); //Place arrow in front of selected item
lcd.write(byte(2));
//Move item + or -
if (last_up== LOW && current_up == HIGH){ //Up
if(onmin3 < 59){
onmin3 ++;
}
else{
onmin3 =0;
}
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
if(onmin3 >0){
onmin3 --;
}
else{
onmin3=59;
}
}
last_down=current_down;
}//subpage1_counter 10
//////////////////////////////////////////////////////////////////////////////////////////////////////
if(subpage1_counter==11)
{
lcd.setCursor(9,2); //Delete last arrow position (onmin1)
lcd.print(" ");
lcd.setCursor(12,2); //Place arrow in front of selected item
lcd.write(byte(2));
//Move item + or -
if (last_up== LOW && current_up == HIGH){ //Up
if(offhour3 < 23){
offhour3++;
}
else{
offhour3 =0;
}
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
if(offhour3 >0){
offhour3--;
}
else{
offhour3=23;
}
}
last_down=current_down;
}//subpage1_counter 11
//////////////////////////////////////////////////////////////////////////////////////////////////////
if(subpage1_counter==12)
{
lcd.setCursor(12,2); //Delete last arrow position (onsec1)
lcd.print(" ");
lcd.setCursor(15,2); //Place arrow in front of selected item
lcd.write(byte(2));
//Move item + or -
if (last_up== LOW && current_up == HIGH){ //Up
if(offmin3 < 59){
offmin3++;
}
else{
offmin3 =0;
}
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
if(offmin3 >0){
offmin3--;
}
else{
offmin3=59;
}
}
last_down=current_down;
}//subpage1_counter 12
////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(subpage1_counter==13)
{
lcd.setCursor(15,2); //Delete last arrow position (back)
lcd.print(" ");
lcd.setCursor(6,3); //Place arrow in front of selected item
lcd.write(byte(2));
//Move item + or -
if (last_up== LOW && current_up == HIGH){ //Up
if(onhour4 < 23){
onhour4 ++;
}
else{
onhour4 =0;
}
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
if(onhour4 >0){
onhour4 --;
}
else{
onhour4=23;
}
}
last_down=current_down;
}//subpage1_counter 13
//////////////////////////////////////////////////////////////////////////////////////////////////////
if(subpage1_counter==14)
{
lcd.setCursor(6,3); //Delete last arrow position (onhour1)
lcd.print(" ");
lcd.setCursor(9,3); //Place arrow in front of selected item
lcd.write(byte(2));
//Move item + or -
if (last_up== LOW && current_up == HIGH){ //Up
if(onmin4 < 59){
onmin4 ++;
}
else{
onmin4 =0;
}
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
if(onmin4 >0){
onmin4 --;
}
else{
onmin4=59;
}
}
last_down=current_down;
}//subpage1_counter 14
//////////////////////////////////////////////////////////////////////////////////////////////////////
if(subpage1_counter==15)
{
lcd.setCursor(9,3); //Delete last arrow position (onmin1)
lcd.print(" ");
lcd.setCursor(12,3); //Place arrow in front of selected item
lcd.write(byte(2));
//Move item + or -
if (last_up== LOW && current_up == HIGH){ //Up
if(offhour4 < 23){
offhour4++;
}
else{
offhour4 =0;
}
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
if(offhour4 >0){
offhour4--;
}
else{
offhour4=23;
}
}
last_down=current_down;
}//subpage1_counter 15
//////////////////////////////////////////////////////////////////////////////////////////////////////
if(subpage1_counter==16)
{
lcd.setCursor(12,3); //Delete last arrow position (onsec1)
lcd.print(" ");
lcd.setCursor(15,3); //Place arrow in front of selected item
lcd.write(byte(2));
//Move item + or -
if (last_up== LOW && current_up == HIGH){ //Up
if(offmin4 < 59){
offmin4++;
}
else{
offmin3 =0;
}
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
if(offmin4 >0){
offmin4--;
}
else{
offmin4=59;
}
}
last_down=current_down;
}//subpage1_counter 16
//////////////////////////////////////////////////////////////////////////////////////////////////////
if(subpage1_counter==17)
{
lcd.setCursor(15,3); //Delete last arrow position (offsec1)
lcd.print(" ");
lcd.setCursor(19,0); //Place arrow in front of selected item
lcd.write(byte(2));
//Move item + or -
if (last_up== LOW && current_up == HIGH){ //Up
lcd.setCursor(19,0); //Delete last arrow position (back) to exit
lcd.print(" ");
subpage1_counter=0; //Exit submenu. Up/down butons enabled to move main pages
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
lcd.setCursor(19,0); //Delete last arrow position (back)
lcd.print(" ");
subpage1_counter=1; //Go to first item (onhour4)
}
last_down=current_down;
}//subpage1_counter 17
//case 2 end
break;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
case 3: //Content and funtions of page 3
lcd.setCursor(0,0);
lcd.print("T1");
lcd.setCursor(3,0);
lcd.print("Mo");
lcd.print(Mon1);
lcd.setCursor(7,0);
lcd.print("Tu");
lcd.print(Tue1);
lcd.setCursor(11,0);
lcd.print("We");
lcd.print(Wed1);
lcd.setCursor(20,0);
lcd.write(byte(1));
lcd.setCursor(1,1);
lcd.print("Th");
lcd.print(Thu1);
lcd.setCursor(5,1);
lcd.print("Fr");
lcd.print(Fri1);
lcd.setCursor(9,1);
lcd.print("Sa");
lcd.print(Sat1);
lcd.setCursor(13,1);
lcd.print("Su");
lcd.print(Sun1);
//------Modifying days states
// Sub counter control
if (last_sel== LOW && current_sel == HIGH){ //select button pressed
if(subpage2_counter <8){ // subpage counter never higher than 8 (total of items)
subpage2_counter ++; //subcounter to move beetwen submenu
}
else{ //If subpage higher than 8 (total of items) return to first item
subpage2_counter=1;
}
}
last_sel=current_sel; //Save last state of select button
//------Days enabled=1 disabled=0.Up button to set 1 , down button to set 0
//First item to control (subpage2_counter=1) Mon1
if(subpage2_counter ==1){
lcd.setCursor(19,0); //Delete last arrow position (back)
lcd.print(" ");
lcd.setCursor(2,0); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Mon1=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Mon1=0;
}
last_down=current_down;
}//subpage2 counter 1
//////////////////////////////////////////////////////////////////////////////////////////////////////
//Second item to control (subpage2_counter=2) Tue1
if(subpage2_counter ==2){
lcd.setCursor(2,0); //Delete last arrow position (Mon1)
lcd.print(" ");
lcd.setCursor(6,0); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Tue1=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Tue1=0;
}
last_down=current_down;
}//subpage2 counter 2
//////////////////////////////////////////////////////////////////////////////////////////////////////
//Tirth item to control (subpage2_counter=3) Wed1
if(subpage2_counter ==3){
lcd.setCursor(6,0); //Delete last arrow position Tue1
lcd.print(" ");
lcd.setCursor(10,0); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Wed1=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Wed1=0;
}
last_down=current_down;
}//subpage2 counter 3
///////////////////////////////////////////////////////////////////////////////////////////////////////
//Fourth item to control (subpage2_counter=4) Thu1
if(subpage2_counter ==4){
lcd.setCursor(10,0); //Delete last arrow position Wed1
lcd.print(" ");
lcd.setCursor(0,1); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Thu1=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Thu1=0;
}
last_down=current_down;
}//subpage2 counter 4
//////////////////////////////////////////////////////////////////////////////////////////////////////
//Fifth item to control (subpage2_counter=5) Fri1
if(subpage2_counter ==5){
lcd.setCursor(0,1); //Delete last arrow position Thu1
lcd.print(" ");
lcd.setCursor(4,1); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Fri1=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Fri1=0;
}
last_down=current_down;
}//subpage2 counter 5
///////////////////////////////////////////////////////////////////////////////////////////////////////
//sixth item to control (subpage2_counter=6) Sat1
if(subpage2_counter ==6){
lcd.setCursor(4,1); //Delete last arrow position Fri1
lcd.print(" ");
lcd.setCursor(8,1); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Sat1=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Sat1=0;
}
last_down=current_down;
}//subpage2 counter 6
///////////////////////////////////////////////////////////////////////////////////////////////////////
//seventh item to control (subpage2_counter=7) Sun1
if(subpage2_counter ==7){
lcd.setCursor(8,1); //Delete last arrow position Sat1
lcd.print(" ");
lcd.setCursor(12,1); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Sun1=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Sun1=0;
}
last_down=current_down;
}//subpage2 counter 7
0
zaratool61
zaratool61

Answer 3 months ago

//////////////////////////////////////////////////////////////////////////////////////////////////////
//eigth item to control (subpage2_counter=8) back
if(subpage2_counter ==8){
lcd.setCursor(12,1); //Delete last arrow position Sun1
lcd.print(" ");
lcd.setCursor(14,0); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
lcd.setCursor(14,0);
lcd.print(" ");
subpage2_counter=0; //Exit submenu
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
subpage2_counter=1;
}
last_down=current_down;
}//subpage2 counter 8
break; //case 3
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
case 4: //Content and funtions of page 3
lcd.setCursor(0,0);
lcd.print("T2");
lcd.setCursor(3,0);
lcd.print("Mo");
lcd.print(Mon2);
lcd.setCursor(7,0);
lcd.print("Tu");
lcd.print(Tue2);
lcd.setCursor(11,0);
lcd.print("We");
lcd.print(Wed2);
lcd.setCursor(15,0);
lcd.write(byte(1));
lcd.setCursor(1,1);
lcd.print("Th");
lcd.print(Thu2);
lcd.setCursor(5,1);
lcd.print("Fr");
lcd.print(Fri2);
lcd.setCursor(9,1);
lcd.print("Sa");
lcd.print(Sat2);
lcd.setCursor(13,1);
lcd.print("Su");
lcd.print(Sun2);
//------Modifying days states
// Sub counter control
if (last_sel== LOW && current_sel == HIGH){ //select button pressed
if(subpage3_counter <8){ // subpage counter never higher than 8 (total of items)
subpage3_counter ++; //subcounter to move beetwen submenu
}
else{ //If subpage higher than 8 (total of items) return to first item
subpage3_counter=1;
}
}
last_sel=current_sel; //Save last state of select button
//------Days enabled=1 disabled=0.Up button to set 1 , down button to set 0
//First item to control (subpage3_counter=1) Mon2
if(subpage3_counter ==1){
lcd.setCursor(14,0); //Delete last arrow position (back)
lcd.print(" ");
lcd.setCursor(2,0); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Mon2=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Mon2=0;
}
last_down=current_down;
}//subpage3 counter 1
///////////////////////////////////////////////////////////////////////////////////////////////////////
//Second item to control (subpage3_counter=2) Tue2
if(subpage3_counter ==2){
lcd.setCursor(2,0); //Delete last arrow position (Mon1)
lcd.print(" ");
lcd.setCursor(6,0); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Tue2=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Tue2=0;
}
last_down=current_down;
}//subpage3 counter 2
//////////////////////////////////////////////////////////////////////////////////////////////////////
//Tirth item to control (subpage3_counter=3) Wed2
if(subpage3_counter ==3){
lcd.setCursor(6,0); //Delete last arrow position Tue1
lcd.print(" ");
lcd.setCursor(10,0); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Wed2=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Wed2=0;
}
last_down=current_down;
}//subpage3 counter 3
//////////////////////////////////////////////////////////////////////////////////////////////////////
//Fourth item to control (subpage3_counter=4) Thu2
if(subpage3_counter ==4){
lcd.setCursor(10,0); //Delete last arrow position Wed1
lcd.print(" ");
lcd.setCursor(0,1); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Thu2=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Thu2=0;
}
last_down=current_down;
}//subpage3 counter 4
//////////////////////////////////////////////////////////////////////////////////////////////////////
//Fifth item to control (subpage3_counter=5) Fri2
if(subpage3_counter ==5){
lcd.setCursor(0,1); //Delete last arrow position Thu1
lcd.print(" ");
lcd.setCursor(4,1); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Fri2=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Fri2=0;
}
last_down=current_down;
}//subpage3 counter 5
//////////////////////////////////////////////////////////////////////////////////////////////////////
//sixth item to control (subpage3_counter=6) Sat2
if(subpage3_counter ==6){
lcd.setCursor(4,1); //Delete last arrow position Fri1
lcd.print(" ");
lcd.setCursor(8,1); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Sat2=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Sat2=0;
}
last_down=current_down;
}//subpage3 counter 6
///////////////////////////////////////////////////////////////////////////////////////////////////////
//seventh item to control (subpage3_counter=7) Sun2
if(subpage3_counter ==7){
lcd.setCursor(8,1); //Delete last arrow position Sat1
lcd.print(" ");
lcd.setCursor(12,1); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Sun2=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Sun2=0;
}
last_down=current_down;
}//subpage3 counter 7
//////////////////////////////////////////////////////////////////////////////////////////////////////
//eigth item to control (subpage3_counter=8) back
if(subpage3_counter ==8){
lcd.setCursor(12,1); //Delete last arrow position Sun1
lcd.print(" ");
lcd.setCursor(14,0); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
lcd.setCursor(14,0);
lcd.print(" ");
subpage3_counter=0; //Exit submenu
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
subpage3_counter=1;
}
last_down=current_down;
}//subpage3 counter 8
//case 4
break;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
case 5: //Content and funtions of page 3
lcd.setCursor(0,0);
lcd.print("T3");
lcd.setCursor(3,0);
lcd.print("Mo");
lcd.print(Mon3);
lcd.setCursor(7,0);
lcd.print("Tu");
lcd.print(Tue3);
lcd.setCursor(11,0);
lcd.print("We");
lcd.print(Wed3);
lcd.setCursor(15,0);
lcd.write(byte(1));
lcd.setCursor(1,1);
lcd.print("Th");
lcd.print(Thu3);
lcd.setCursor(5,1);
lcd.print("Fr");
lcd.print(Fri3);
lcd.setCursor(9,1);
lcd.print("Sa");
lcd.print(Sat3);
lcd.setCursor(13,1);
lcd.print("Su");
lcd.print(Sun3);
//------Modifying days states
// Sub counter control
if (last_sel== LOW && current_sel == HIGH){ //select button pressed
if(subpage4_counter <8){ // subpage counter never higher than 8 (total of items)
subpage4_counter ++; //subcounter to move beetwen submenu
}
else{ //If subpage higher than 8 (total of items) return to first item
subpage4_counter=1;
}
}
last_sel=current_sel; //Save last state of select button
//------Days enabled=1 disabled=0.Up button to set 1 , down button to set 0
//First item to control (subpage4_counter=1) Mon3
if(subpage4_counter ==1){
lcd.setCursor(14,0); //Delete last arrow position (back)
lcd.print(" ");
lcd.setCursor(2,0); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Mon3=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Mon3=0;
}
last_down=current_down;
}//subpage4 counter 1
//////////////////////////////////////////////////////////////////////////////////////////////////////
//Second item to control (subpage4_counter=2) Tue3
if(subpage4_counter ==2){
lcd.setCursor(2,0); //Delete last arrow position (Mon1)
lcd.print(" ");
lcd.setCursor(6,0); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Tue3=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Tue3=0;
}
last_down=current_down;
}//subpage4 counter 2
//////////////////////////////////////////////////////////////////////////////////////////////////////
//Tirth item to control (subpage4_counter=3) Wed3
if(subpage4_counter ==3){
lcd.setCursor(6,0); //Delete last arrow position Tue1
lcd.print(" ");
lcd.setCursor(10,0); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Wed3=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Wed3=0;
}
last_down=current_down;
}//subpage4 counter 3
///////////////////////////////////////////////////////////////////////////////////////////////////////
//Fourth item to control (subpage4_counter=4) Thu3
if(subpage4_counter ==4){
lcd.setCursor(10,0); //Delete last arrow position Wed1
lcd.print(" ");
lcd.setCursor(0,1); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Thu3=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Thu3=0;
}
last_down=current_down;
}//subpage4 counter 4
//////////////////////////////////////////////////////////////////////////////////////////////////////
//Fifth item to control (subpage4_counter=5) Fri3
if(subpage4_counter ==5){
lcd.setCursor(0,1); //Delete last arrow position Thu1
lcd.print(" ");
lcd.setCursor(4,1); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Fri3=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Fri3=0;
}
last_down=current_down;
}//subpage4 counter 5
//////////////////////////////////////////////////////////////////////////////////////////////////////
//sixth item to control (subpage2_counter=6) Sat3
if(subpage4_counter ==6){
lcd.setCursor(4,1); //Delete last arrow position Fri1
lcd.print(" ");
lcd.setCursor(8,1); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Sat3=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Sat3=0;
}
last_down=current_down;
}//subpage4 counter 6
//////////////////////////////////////////////////////////////////////////////////////////////////////
//seventh item to control (subpage4_counter=7) Sun3
if(subpage4_counter ==7){
lcd.setCursor(8,1); //Delete last arrow position Sat1
lcd.print(" ");
lcd.setCursor(12,1); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Sun3=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Sun3=0;
}
last_down=current_down;
}//subpage4 counter 7
//////////////////////////////////////////////////////////////////////////////////////////////////////
//eigth item to control (subpage4_counter=8) back
if(subpage4_counter ==8){
lcd.setCursor(12,1); //Delete last arrow position Sun1
lcd.print(" ");
lcd.setCursor(14,0); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
lcd.setCursor(14,0);
lcd.print(" ");
subpage4_counter=0; //Exit submenu
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
subpage4_counter=1;
}
last_down=current_down;
}//subpage4 counter 8
//case 5
break;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
case 6: //Content and funtions of page 3
lcd.setCursor(0,0);
lcd.print("T4");
lcd.setCursor(3,0);
lcd.print("Mo");
lcd.print(Mon4);
lcd.setCursor(7,0);
lcd.print("Tu");
lcd.print(Tue4);
lcd.setCursor(11,0);
lcd.print("We");
lcd.print(Wed4);
lcd.setCursor(15,0);
lcd.write(byte(1));
lcd.setCursor(1,1);
lcd.print("Th");
lcd.print(Thu4);
lcd.setCursor(5,1);
lcd.print("Fr");
lcd.print(Fri4);
lcd.setCursor(9,1);
lcd.print("Sa");
lcd.print(Sat4);
lcd.setCursor(13,1);
lcd.print("Su");
lcd.print(Sun4);
//------Modifying days states
// Sub counter control
if (last_sel== LOW && current_sel == HIGH){ //select button pressed
if(subpage5_counter <8){ // subpage counter never higher than 8 (total of items)
subpage5_counter ++; //subcounter to move beetwen submenu
}
else{ //If subpage higher than 8 (total of items) return to first item
subpage5_counter=1;
}
}
last_sel=current_sel; //Save last state of select button
//------Days enabled=1 disabled=0.Up button to set 1 , down button to set 0
//First item to control (subpage5_counter=1) Mon4
if(subpage5_counter ==1){
lcd.setCursor(14,0); //Delete last arrow position (back)
lcd.print(" ");
lcd.setCursor(2,0); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Mon4=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Mon4=0;
}
last_down=current_down;
}//subpage5 counter 1
///////////////////////////////////////////////////////////////////////////////////////////////////////
//Second item to control (subpage5_counter=2) Tue4
if(subpage5_counter ==2){
lcd.setCursor(2,0); //Delete last arrow position (Mon1)
lcd.print(" ");
lcd.setCursor(6,0); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Tue4=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Tue4=0;
}
last_down=current_down;
}//subpage5 counter 2
///////////////////////////////////////////////////////////////////////////////////////////////////////
//Tirth item to control (subpage5_counter=3) Wed4
if(subpage5_counter ==3){
lcd.setCursor(6,0); //Delete last arrow position Tue1
lcd.print(" ");
lcd.setCursor(10,0); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Wed4=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Wed4=0;
}
last_down=current_down;
}//subpage5 counter 3
//////////////////////////////////////////////////////////////////////////////////////////////////////
//Fourth item to control (subpage5_counter=4) Thu4
if(subpage5_counter ==4){
lcd.setCursor(10,0); //Delete last arrow position Wed1
lcd.print(" ");
lcd.setCursor(0,1); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Thu4=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Thu4=0;
}
last_down=current_down;
}//subpage5 counter 4
//////////////////////////////////////////////////////////////////////////////////////////////////////
//Fifth item to control (subpage5_counter=5) Fri4
if(subpage5_counter ==5){
lcd.setCursor(0,1); //Delete last arrow position Thu1
lcd.print(" ");
lcd.setCursor(4,1); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Fri4=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Fri4=0;
}
last_down=current_down;
}//subpage5 counter 5
//////////////////////////////////////////////////////////////////////////////////////////////////////
//sixth item to control (subpage5_counter=6) Sat4
if(subpage5_counter ==6){
lcd.setCursor(4,1); //Delete last arrow position Fri1
lcd.print(" ");
lcd.setCursor(8,1); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Sat4=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Sat4=0;
}
last_down=current_down;
}//subpage5 counter 6
///////////////////////////////////////////////////////////////////////////////////////////////////////
//seventh item to control (subpage5_counter=7) Sun4
if(subpage5_counter ==7){
lcd.setCursor(8,1); //Delete last arrow position Sat1
lcd.print(" ");
lcd.setCursor(12,1); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
Sun4=1;
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
Sun4=0;
}
last_down=current_down;
}//subpage5 counter 7
//////////////////////////////////////////////////////////////////////////////////////////////////////
//eigth item to control (subpage5_counter=8) back
if(subpage5_counter ==8){
lcd.setCursor(12,1); //Delete last arrow position Sun1
lcd.print(" ");
lcd.setCursor(14,0); //Place arrow in front of selected item
lcd.write(byte(2));
if (last_up== LOW && current_up == HIGH){ //Up
lcd.setCursor(14,0);
lcd.print(" ");
subpage5_counter=0; //Exit submenu
}
last_up=current_up;
if(last_down== LOW && current_down == HIGH){//Down
subpage5_counter=1;
}
last_down=current_down;
}//subpage5 counter 8
//case 6
break;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
case 7: //Page 4 display and functions
lcd.setCursor(4,0);
lcd.print("KAYDETMEK ICIN");
lcd.setCursor(7,1);
lcd.print("-AYAR-");
lcd.setCursor(2,3);
lcd.print("DUGMESINE BASIN");
if (last_sel== LOW && current_sel == HIGH){ //select button pressed.Save settings to eeprom
EEPROM.write(0, onhour1);
EEPROM.write(1, onmin1);
EEPROM.write(2, offhour1);
EEPROM.write(3, offmin1);
EEPROM.write(4, onhour2);
EEPROM.write(5, onmin2);
EEPROM.write(6, offhour2);
EEPROM.write(7, offmin2);
EEPROM.write(8, onhour3);
EEPROM.write(9, onmin3);
EEPROM.write(10, offhour3);
EEPROM.write(11, offmin3);
EEPROM.write(12, onhour4);
EEPROM.write(13, onmin4);
EEPROM.write(14, offhour4);
EEPROM.write(15, offmin4);
EEPROM.write(16, Sun1);
EEPROM.write(17, Mon1);
EEPROM.write(18, Tue1);
EEPROM.write(19, Wed1);
EEPROM.write(20, Thu1);
EEPROM.write(21, Fri1);
EEPROM.write(22, Sat1);
EEPROM.write(23, Sun2);
EEPROM.write(24, Mon2);
EEPROM.write(25, Tue2);
EEPROM.write(26, Wed2);
EEPROM.write(27, Thu2);
EEPROM.write(28, Fri2);
EEPROM.write(29, Sat2);
EEPROM.write(30, Sun3);
EEPROM.write(31, Mon3);
EEPROM.write(32, Tue3);
EEPROM.write(33, Wed3);
EEPROM.write(34, Thu3);
EEPROM.write(35, Fri3);
EEPROM.write(36, Sat3);
EEPROM.write(37, Sun4);
EEPROM.write(38, Mon4);
EEPROM.write(39, Tue4);
EEPROM.write(40, Wed4);
EEPROM.write(41, Thu4);
EEPROM.write(42, Fri4);
EEPROM.write(43, Sat4);
lcd.clear(); //Print message "SAVED!"
lcd.setCursor(5,1);
lcd.print("KAYDEDILDI!");
delay(2000);
lcd.clear(); //Clear lcd and go to main page
page_counter=1;
}
last_sel=current_sel; //Save last state of select button
//Case 7
break;
}//switch
//-------------Convertion----------//
//---------Converting clock time into single number
Hour = now.hour();
Min = now.minute();
Time = (Hour*10000+ Min*100 );
//--------Converting first timer on/off into single number////////////////////////////
on_hour1=onhour1;
on_min1=onmin1;
on_Time1=(on_hour1*10000 + on_min1*100 );
off_hour1=offhour1;
off_min1=offmin1;
off_Time1=(off_hour1*10000 + off_min1*100 );
//--------Converting second timer on/off into single number///////////////////////////
on_hour2=onhour2;
on_min2=onmin2;
on_Time2=(on_hour2*10000 + on_min2*100);
off_hour2=offhour2;
off_min2=offmin2;
off_Time2=(off_hour2*10000 + off_min2*100);
//--------Converting third timer on/off into single number/////////////////////////////
on_hour3=onhour3;
on_min3=onmin3;
on_Time3=(on_hour3*10000 + on_min3*100);
off_hour3=offhour3;
off_min3=offmin3;
off_Time3=(off_hour3*10000 + off_min3*100 );
//--------Converting fourth timer on/off into single number////////////////////////////
on_hour4=onhour4;
on_min4=onmin4;
on_Time4=(on_hour4*10000 + on_min4*100 );
off_hour4=offhour4;
off_min4=offmin4;
off_Time4=(off_hour4*10000 + off_min4*100);
//----Relay Function per day----///////////////////////////////////////////////////////
switch(now.dayOfTheWeek()) //now.dayOfTheWeek values 1 to 7, monday to sunday
{
case 1: //If monday
if(Mon1==1){
First_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 2: //If tuesday
if(Tue1==1){
First_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 3: //If wednesday
if(Wed1==1){
First_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 4: //If thursday
if(Thu1==1){
First_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
/////////////////////////////
case 5: //If friday
if(Fri1==1)
{
First_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 6: //If saturday
if(Sat1==1)
{
First_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 7: //If sunday
if(Sun1==1)
{
First_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
//////////////////////////////////////////////////////////////////////////////////////
case 8: //If monday
if(Mon2==1)
{
Second_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 9: //If tuesday
if(Tue2==1)
{
Second_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 10: //If wednesday
if(Wed2==1)
{
Second_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 11: //If thursday
if(Thu2==1)
{
Second_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 12: //If friday
if(Fri2==1)
{
Second_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 13: //If saturday
if(Sat2==1)
{
Second_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 14: //If sunday
if(Sun2==1)
{
Second_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
//////////////////////////////////////////////////////////////////////////////////////////////////////
case 15: //If monday
if(Mon3==1)
{
Third_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 16: //If tuesday
if(Tue3==1)
{
Third_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 17: //If wednesday
if(Wed3==1)
{
Third_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 18: //If thursday
if(Thu3==1)
{
Third_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 19: //If friday
if(Fri3==1)
{
Third_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 20: //If saturday
if(Sat3==1)
{
Third_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 21: //If sunday
if(Sun3==1)
{
Third_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////////////////////////////////////////////////////////////////////////////
case 22: //If monday
if(Mon4==1)
{
Fourth_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 23: //If tuesday
if(Tue4==1)
{
Fourth_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 24: //If wednesday
if(Wed4==1)
{
Fourth_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 25: //If thursday
if(Thu4==1)
{
Fourth_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 26: //If friday
if(Fri4==1)
{
Fourth_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 27: //If saturday
if(Sat4==1)
{
Fourth_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
////////////////////////////
case 28: //If sunday
if(Sun4==1)
{
Fourth_Timer();
}
else
{
digitalWrite(Relay1, LOW);
}
break;
}//switch day
}//void loop
////////////////////////////////////////////////////////////////////////////////////////////
void First_Timer() //Custom function to check timer
{
if(onhour1 == offhour1 && onmin1==offmin1 )
{
digitalWrite(Relay1, LOW);
}
if(on_Time1 < off_Time1)
{
if(Time >= on_Time1 && Time < off_Time1) //Start
{
digitalWrite(Relay1, HIGH);
}
else if(Time >= off_Time1)
{
digitalWrite(Relay1, LOW);
}
else{
digitalWrite(Relay1, LOW);
}
}
if (on_Time1 > off_Time1)
{
if(Time >= on_Time1 && Time <= 235959 )//Start
{
digitalWrite(Relay1, HIGH);
}
else if(Time < off_Time1)
{
digitalWrite(Relay1, HIGH);
}
else if(Time >= off_Time1 && Time < on_Time1)
{
digitalWrite(Relay1, LOW);
}
}
}//First timer
//////////////////////////////////////////////////////////////////////////////////////////////////////
void Second_Timer() //Custom function to check timer
{
if(onhour2 == offhour2 && onmin2==offmin2)
{
digitalWrite(Relay1, LOW);
}
if(on_Time2 < off_Time2 )
{
if(Time >= on_Time2 && Time < off_Time2) //Start
{
digitalWrite(Relay1, HIGH);
}
else if(Time >= off_Time2)
{
digitalWrite(Relay1, LOW);
}
else
{
digitalWrite(Relay1, LOW);
}
}
if (on_Time2 > off_Time2)
{
if(Time >= on_Time2 && Time <= 235959 )//Start
{
digitalWrite(Relay1, HIGH);
}
else if(Time < off_Time2 )
{
digitalWrite(Relay1, HIGH);
}
else if(Time >= off_Time2 && Time < on_Time2)
{
digitalWrite(Relay1, LOW);
}
}
} //Second Timer
//////////////////////////////////////////////////////////////////////////////////////////////////////
void Third_Timer() //Custom function to check timer
{
if(onhour3 == offhour3 && onmin3==offmin3 )
{
digitalWrite(Relay1, LOW);
}
if(on_Time3 < off_Time3 )
{
if(Time >= on_Time3 && Time < off_Time3 ) //Start
{
digitalWrite(Relay1, HIGH);
}
else if(Time >= off_Time3 )
{
digitalWrite(Relay1, LOW);
}
else{
digitalWrite(Relay1, LOW);
}
}
if (on_Time3 > off_Time3)
{
if(Time >= on_Time3 && Time <= 235959 ) //Start
{
digitalWrite(Relay1, HIGH);
}
else if(Time < off_Time3 )
{
digitalWrite(Relay1, HIGH);
}
else if(Time >= off_Time3 && Time < on_Time3)
{
digitalWrite(Relay1, LOW);
}
}
} // Third Timer
//////////////////////////////////////////////////////////////////////////////////////////////////////
void Fourth_Timer() //Custom function to check timer
{
if(onhour4 == offhour4 && onmin4==offmin4)
{
digitalWrite(Relay1, LOW);
}
if(on_Time4 < off_Time4 )
{
if(Time >= on_Time4 && Time < off_Time4)//Start
{
digitalWrite(Relay1, HIGH);
}
else if(Time >= off_Time4)
{
digitalWrite(Relay1, LOW);
}
else
{
digitalWrite(Relay1, LOW);
}
}
if (on_Time4 > off_Time4 )
{
if(Time >= on_Time4 && Time <= 235959 )//Start
{
digitalWrite(Relay1, HIGH);
}
else if(Time < off_Time4)
{
digitalWrite(Relay1, HIGH);
}
else if(Time >= off_Time4 && Time < on_Time4)
{
digitalWrite(Relay1, LOW);
}
}
} //Fourth Timer
///////////////////////////////////////////////////////////////////////////////////////////

0
zaratool61
zaratool61

Tip 3 months ago

I can throw the whole code to you. What is your e-mail address?
0
NicolasJ7
NicolasJ7

Reply 3 months ago

It's not compiling or not working?

0
zaratool61
zaratool61

Reply 3 months ago

Compiling but not running.

0
NicolasJ7
NicolasJ7

Reply 3 months ago

inbox

0
zaratool61
zaratool61

Question 3 months ago


Because I'm so new; Why does this code not work.
I'm trying to make more than one timer per week



Hour = now.hour();
Min = now.minute();
Time = (Hour*10000+ Min*100 );
//--------Converting first timer on/off into single number
on_hour1=onhour1;
on_min1=onmin1;
on_Time1=(on_hour1*10000 + on_min1*100 );
off_hour1=offhour1;
off_min1=offmin1;
off_Time1=(off_hour1*10000 + off_min1*100 );
//--------Converting second timer on/off into single number
on_hour2=onhour2;
on_min2=onmin2;
on_Time2=(on_hour2*10000 + on_min2*100);
off_hour2=offhour2;
off_min2=offmin2;
off_Time2=(off_hour2*10000 + off_min2*100);
//--------Converting third timer on/off into single number
on_hour3=onhour3;
on_min3=onmin3;
on_Time3=(on_hour3*10000 + on_min3*100);
off_hour3=offhour3;
off_min3=offmin3;
off_Time3=(off_hour3*10000 + off_min3*100 );
//--------Converting fourth timer on/off into single number
on_hour4=onhour4;
on_min4=onmin4;
on_Time4=(on_hour4*10000 + on_min4*100 );
off_hour4=offhour4;
off_min4=offmin4;
off_Time4=(off_hour4*10000 + off_min4*100);
//----Relay Function per day----//
switch(now.dayOfTheWeek()){ //now.dayOfTheWeek values 1 to 7, monday to sunday
case 1: //If monday
if(Mon1==1){
First_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 2: //If tuesday
if(Tue1==1){
First_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 3: //If wednesday
if(Wed1==1){
First_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 4: //If thursday
if(Thu1==1){
First_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 5: //If friday
if(Fri1==1){
First_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 6: //If saturday
if(Sat1==1){
First_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 7: //If sunday
if(Sun1==1){
First_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 8: //If monday
if(Mon2==1){
Second_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 9: //If tuesday
if(Tue2==1){
Second_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 10: //If wednesday
if(Wed2==1){
Second_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 11: //If thursday
if(Thu2==1){
Second_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 12: //If friday
if(Fri2==1){
Second_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 13: //If saturday
if(Sat2==1){
Second_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 14: //If sunday
if(Sun2==1){
Second_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 15: //If monday
if(Mon3==1){
Third_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 16: //If tuesday
if(Tue3==1){
Third_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 17: //If wednesday
if(Wed3==1){
Third_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 18: //If thursday
if(Thu3==1){
Third_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 19: //If friday
if(Fri3==1){
Third_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 20: //If saturday
if(Sat3==1){
Third_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 21: //If sunday
if(Sun3==1){
Third_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 22: //If monday
if(Mon4==1){
Fourth_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 23: //If tuesday
if(Tue4==1){
Fourth_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 24: //If wednesday
if(Wed4==1){
Fourth_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 25: //If thursday
if(Thu4==1){
Fourth_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 26: //If friday
if(Fri4==1){
Fourth_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 27: //If saturday
if(Sat4==1){
Fourth_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
case 28: //If sunday
if(Sun4==1){
Fourth_Timer();
}
else{
digitalWrite(Relay1, LOW);
}
break;
}
void First_Timer() { //Custom function to check timer
if(onhour1 == offhour1 && onmin1==offmin1 ){
digitalWrite(Relay1, LOW);
}
if(on_Time1 < off_Time1){
if(Time >= on_Time1 && Time < off_Time1){ //Start
digitalWrite(Relay1, HIGH);
}
else if(Time >= off_Time1) {
digitalWrite(Relay1, LOW);
}
else{
digitalWrite(Relay1, LOW);
}
}
if (on_Time1 > off_Time1){
if(Time >= on_Time1 && Time <= 235959 ){ //Start
digitalWrite(Relay1, HIGH);
}
else if(Time < off_Time1){
digitalWrite(Relay1, HIGH);
}
else if(Time >= off_Time1 && Time < on_Time1){
digitalWrite(Relay1, LOW);
}
}
}
void Second_Timer() { //Custom function to check timer
if(onhour2 == offhour2 && onmin2==offmin2){
digitalWrite(Relay1, LOW);
}
if(on_Time2 < off_Time2 ){
if(Time >= on_Time2 && Time < off_Time2){ //Start
digitalWrite(Relay1, HIGH);
}
else if(Time >= off_Time2) {
digitalWrite(Relay1, LOW);
}
else{
digitalWrite(Relay1, LOW);
}
}
if (on_Time2 > off_Time2){
if(Time >= on_Time2 && Time <= 235959 ){ //Start
digitalWrite(Relay1, HIGH);
}
else if(Time < off_Time2 ){
digitalWrite(Relay1, HIGH);
}
else if(Time >= off_Time2 && Time < on_Time2){
digitalWrite(Relay1, LOW);
}
}
}
void Third_Timer() { //Custom function to check timer
if(onhour3 == offhour3 && onmin3==offmin3 ){
digitalWrite(Relay1, LOW);
}
if(on_Time3 < off_Time3 ){
if(Time >= on_Time3 && Time < off_Time3 ){ //Start
digitalWrite(Relay1, HIGH);
}
else if(Time >= off_Time3 ) {
digitalWrite(Relay1, LOW);
}
else{
digitalWrite(Relay1, LOW);
}
}
if (on_Time3 > off_Time3){
if(Time >= on_Time3 && Time <= 235959 ){ //Start
digitalWrite(Relay1, HIGH);
}
else if(Time < off_Time3 ){
digitalWrite(Relay1, HIGH);
}
else if(Time >= off_Time3 && Time < on_Time3){
digitalWrite(Relay1, LOW);
}
}
}
void Fourth_Timer() { //Custom function to check timer
if(onhour4 == offhour4 && onmin4==offmin4){
digitalWrite(Relay1, LOW);
}
if(on_Time4 < off_Time4 ){
if(Time >= on_Time4 && Time < off_Time4){ //Start
digitalWrite(Relay1, HIGH);
}
else if(Time >= off_Time4) {
digitalWrite(Relay1, LOW);
}
else{
digitalWrite(Relay1, LOW);
}
}
if (on_Time4 > off_Time4 ){
if(Time >= on_Time4 && Time <= 235959 ){ //Start
digitalWrite(Relay1, HIGH);
}
else if(Time < off_Time4){
digitalWrite(Relay1, HIGH);
}
else if(Time >= off_Time4 && Time < on_Time4){
digitalWrite(Relay1, LOW);
}
}
}


0
NicolasJ7
NicolasJ7

Answer 3 months ago

I can't see the variables.

0
zaratool61
zaratool61

Reply 3 months ago

#include <EEPROM.h>
#include <RTClib.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20,2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);//0x3F is my lcd address, maybe not yours!
RTC_DS3231 rtc;
char daysOfTheWeek[7][12] = {"Paz", "Pzt", "Sal", "Car", "Per", "Cum", "Cmt"};
//-----------------------//
//------Variables--------//
//-----------------------//
//------First Timer
byte onhour1;
byte onmin1;
byte offhour1;
byte offmin1;
//-----Second Timer
byte onhour2;
byte onmin2;
byte offhour2;
byte offmin2;
//-----Third Timer
byte onhour3;
byte onmin3;
byte offhour3;
byte offmin3;
//-----Fourth Timer
byte onhour4;
byte onmin4;
byte offhour4;
byte offmin4;
//------Days of the week
boolean Sun1;
boolean Mon1;
boolean Tue1;
boolean Wed1;
boolean Thu1;
boolean Fri1;
boolean Sat1;
boolean Sun2;
boolean Mon2;
boolean Tue2;
boolean Wed2;
boolean Thu2;
boolean Fri2;
boolean Sat2;
boolean Sun3;
boolean Mon3;
boolean Tue3;
boolean Wed3;
boolean Thu3;
boolean Fri3;
boolean Sat3;
boolean Sun4;
boolean Mon4;
boolean Tue4;
boolean Wed4;
boolean Thu4;
boolean Fri4;
boolean Sat4;
//------Pages or menus
int page_counter=1;
int subpage1_counter=0;
int subpage2_counter=0;
int subpage3_counter=0;
int subpage4_counter=0;
int subpage5_counter=0;
//-------To convert clock into single number
unsigned long Time;
unsigned long Hour;
unsigned long Min;
//------To convert first timer into Single number
unsigned long on_Time1;
unsigned long on_hour1;
unsigned long on_min1;
unsigned long off_Time1;
unsigned long off_hour1;
unsigned long off_min1;
//------To convert second timer into Single number
unsigned long on_Time2;
unsigned long on_hour2;
unsigned long on_min2;
unsigned long off_Time2;
unsigned long off_hour2;
unsigned long off_min2;
//------To convert Third timer into Single number
unsigned long on_Time3;
unsigned long on_hour3;
unsigned long on_min3;
unsigned long off_Time3;
unsigned long off_hour3;
unsigned long off_min3;
//------To convert Fourth timer into Single number
unsigned long on_Time4;
unsigned long on_hour4;
unsigned long on_min4;
unsigned long off_Time4;
unsigned long off_hour4;
unsigned long off_min4;
//-------Push buttons current/last state
boolean current_up = LOW;
boolean last_up=LOW;
boolean current_sel = LOW;
boolean last_sel = LOW;
boolean last_down = LOW;
boolean current_down = LOW;
//-------Pins
byte Relay1 =13;//Relay to pin 13
int up=2; //Up button to pin 2
int sel=3; //Select button to pin 3
int down=4; //Down button to pin 4
char t[32];
//Custom return char
byte back[8] = {
0b00100,
0b01000,
0b11111,
0b01001,
0b00101,
0b00001,
0b00001,
0b11111
};
//Custom arrow char
byte arrow[8] = {
0b01000,
0b00100,
0b00010,
0b11111,
0b00010,
0b00100,
0b01000,
0b00000
};
void setup() {
pinMode(Relay1, OUTPUT);
Wire.begin();
rtc.begin();
lcd.begin(20,4);
lcd.backlight();
lcd.clear();
lcd.createChar(1, back);//Custom chars
lcd.createChar(2, arrow);
rtc.adjust(DateTime(2020, 9, 30, 0, 0, 0));
//--------eePROM read values-------//
//------First Timer
onhour1=EEPROM.read(0);
onmin1=EEPROM.read(1);
offhour1=EEPROM.read(2);
offmin1=EEPROM.read(3);
//------Second Timer
onhour2=EEPROM.read(4);
onmin2=EEPROM.read(5);
offhour2=EEPROM.read(6);
offmin2=EEPROM.read(7);
//------Third Timer
onhour3=EEPROM.read(8);
onmin3=EEPROM.read(9);
offhour3=EEPROM.read(10);
offmin3=EEPROM.read(11);
//------Fourth Timer
onhour4=EEPROM.read(12);
onmin4=EEPROM.read(13);
offhour4=EEPROM.read(14);
offmin4=EEPROM.read(15);
//-----Week Timer
Sun1=EEPROM.read(16);
Mon1=EEPROM.read(17);
Tue1=EEPROM.read(18);
Wed1=EEPROM.read(19);
Thu1=EEPROM.read(20);
Fri1=EEPROM.read(21);
Sat1=EEPROM.read(22);
Sun2=EEPROM.read(23);
Mon2=EEPROM.read(24);
Tue2=EEPROM.read(25);
Wed2=EEPROM.read(26);
Thu2=EEPROM.read(27);
Fri2=EEPROM.read(28);
Sat2=EEPROM.read(29);
Sun3=EEPROM.read(30);
Mon3=EEPROM.read(31);
Tue3=EEPROM.read(32);
Wed3=EEPROM.read(33);
Thu3=EEPROM.read(34);
Fri3=EEPROM.read(35);
Sat3=EEPROM.read(36);
Sun4=EEPROM.read(37);
Mon4=EEPROM.read(38);
Tue4=EEPROM.read(39);
Wed4=EEPROM.read(40);
Thu4=EEPROM.read(41);
Fri4=EEPROM.read(42);
Sat4=EEPROM.read(43);
}
//---- De-bouncing function for all buttons----//
boolean debounce(boolean last, int pin)
{
boolean current = digitalRead(pin);
if (last != current)
{
delay(10);
current = digitalRead(pin);
}
return current;
}
void loop() {

0
zaratool61
zaratool61

Question 3 months ago

I wonder how can I adjust the clock using the buttons. I am very new in this business

0
NicolasJ7
NicolasJ7

Answer 3 months ago

Take a look at the "DS3231" examples. You will find "DS3231_set". Use the functions Clock.setYear(), Clock.setMonth(), etc to modify your settings inside the " () ".

0
zaratool61
zaratool61

Reply 3 months ago

Thank You
0
kurtosbrasil
kurtosbrasil

Question 4 months ago

Hi Nicolas , one other question , could 1 replace the buttons with single on/off , if so, how should my code be? and my wiring?

0
NicolasJ7
NicolasJ7

Answer 4 months ago

Yes, you can. You must need to add another button (on/off) and declare an "if" statement from the begin of the code to condition the void loop to work or not according to the buttons state.

0
kurtosbrasil
kurtosbrasil

Reply 4 months ago

Ok, thanks

0
SatishK105
SatishK105

2 years ago

i tried to build this but there are some problems which i am facing..
The display is not showing time, instead it is showing what is in pic.

IMG_20181117_031952.jpg