RTC Clock Programming Difficulty

I am using an Arduino Mega 2560 to drive a Nixie Tube based clock. I have all of the tubes correctly being driven for pulling the time data from the RTC clock module (Hours, min, sec) and the date and month. I can see through the serial port all of this is correct. I programmed lines of code to enable the clock user to adjust the time (via pushbutton inputs) for daylight savings and THAT section of the program works fine. That portion works by holding down an input button and the clock displays the time and rolls the hours or minutes accordingly and then it resets the RTC for the new time.

However... Here is my problem... I used the same format of programming to change the date for the day and month but I cannot get the display nor the RTC to change the date internally, because if it did change I believe I would see this on the nixies tubes, and the serial port is showing me that the date is indeed NOT CHANGING ! UGH ! I played around with moving the subroutines and streamlining the program for faster flow but that is not the issue. I believe the coding has a problem or I am continuing to overwrite the new date with the old in RTC memory (?).

ANY help would be appreciated THANKS in advance....
Badjer

This is the section that works....

void ChangeTime()
{
byte prevHour = t.hour;
byte prevMin = t.min;
byte prevSec = t.sec;
int newHour, newMin;
newHour = prevHour;
newMin = prevMin;
if(but0state == HIGH)
{// Increment the Hour up by 1
newHour = prevHour+1;
DisplayTime();
DriveTubes();
if(newHour>=24) newHour=0;
}
else if(but1state == HIGH)
{// Decrement the Hour down by one
newHour=prevHour-1;
DisplayTime();
DriveTubes();
if(newHour<=0) newHour=23;
}
if(but2state == HIGH)
{// Increment the Minute up by one
newMin = prevMin+1;
DisplayTime();
DriveTubes();
if(newMin>59) newMin=0;
}
else if(but3state == HIGH)
{// Decrement Minute down by one
newMin=prevMin-1;
DisplayTime();
DriveTubes();
if(newMin<0) newMin=59;
}
rtc.setTime(newHour,newMin,prevSec);
}

The problem section....

void ChangeDate()
{
byte prevDate = t.date;
byte prevMonth = t.mon;
byte prevYear = t.year;
int newDate, newMonth, newYear;
newDate = prevDate;
newMonth = prevMonth;
if(but4state == HIGH)
{// Increment the DATE up by 1
newDate = prevDate+1;
DisplayDate();
DriveTubes();
if(newDate>=32) newDate=1;
}
else if(but5state == HIGH)
{// Increment the Month by one
newMonth=prevMonth+1;
DisplayDate();
DriveTubes();
if(newMonth>=13) newMonth=1;
}
rtc.setDate(newDate,newMonth,newYear);
}

FULL CODE BELOW:

Welcome to the Forum. Please read these two posts:

General Guidance and How to use the Forum
and
Read this before posting a programming question ...
You may also find useful information that would answer your question here:
Useful links - check here for reference posts / tutorials

It is important to provide as much of the information that is needed to solve your problem as you can, in your first posts. The forum link above has guidelines for posting in a standard way that makes it easiest for people to provide you with useful answers. Making an effort to do this will greatly increase the number and quality of helpful responses that you get.

You have added your sketch as an attachment. Unless the sketch is too large, it's better if you post your code (using code tags!), rather than attach it. When it's attached, we have to download it, create a folder then open your code in our IDE. And afterwards, the folder remains unless we navigate to the "Temp" folder and manually remove it. It's much easier to just view the code in your post.
Please edit your post and insert your code inside it, using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons. The "Code: [Select]" feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing.

I tried posting my code using the code tag but it errors out "over 9000 characters." So here is the attachment again... sorry...! :o(

RTC Clock Wont reset.doc (110 KB)

Please remove that attachment and repost it as a plain text file. Not a PDF and not a DOC.

Your instructions state a .doc file is acceptable.

Do you mean this forum message that appears when you upload?

Allowed file types: doc, gif, jpg, mpg, pdf, png, txt, zip, c, h, cpp, ino, pde

?

That is just a forum software requirement, and has nothing to do with making your code easy to work with. Many people won't open a doc file, I know it may seem that I am being petty, but actually you will get a lot more real help if you post files in the format that they were created. There are fewer side effects and it is easier to import into an IDE as raw text.

Nevermind I figured it out... Solution below...

int d = 1;
int m = 11;
int y = 2020;

void ChangeDate()
{
d = t.date;
m = t.mon;
y = t.year;
if(but4state == HIGH)
{// Increment the DATE up by 1
d = d + 1;
DisplayDate();
DriveTubes();
if(d >= 32) d = 1;
delay(700);
}
else if(but5state == HIGH)
{// Increment the Month by one
m = m + 1;
DisplayDate();
DriveTubes();
if(m >= 13) m = 1;
delay(700);
}
rtc.setDate(d,m,y);
//rtc.setDate(23,6,2020);
}

Well, the instructions to post an attachment then are not at all clear and if it is limited to 9000 characters, then it should suggest an attachment in the error code, and there tell the user what types to post in. I'm just letting you know as a user that it should be improved to avoid the multiple postings talking through site issues versus helping get the learning to the masses. #JustSayin.

The forum maintainers can only make certain changes to configure the forum software, it is mostly beyond their control. However, a big effort has been made to provide specific instructions in the sticky threads at the top of the forum. Unfortunately people don't often read them before posting. Suggestions to fix that, for example by printing them in red, were met with the same obstacle of no support in the forum software. In fact, I could not find any statement there about file types. It's not a law or anything, the only reason I brought it up is because I have been around here long enough to know that some people would definitely pass over it.