DS1302 OLED Alarm Clock

I was programmed an Arduino alarm clock project using DS1302, OLED and three buttons. So I included time and alarm editing part using buttons.
my Day of week variable was integer.

int DyWeek = 2;

I set time as following code and its OK. All variables assigned as integers

myRTC.setDS1302Time(00, m, h, DyWeek, D, M, Y);

Then I design my Day of week editing function as follows. subframes were design to change steps.

  if (subframe == 4) {
    display.setCursor(0, 0);
    display.print("Set Day of Week");
    display.setCursor(0, 10);
    display.print(">>> ");
    display.display();
    if (digitalRead(btnChange) == LOW) {
      DyWeek++;
      if (DyWeek < 8) {
        DyWeek = 1;
      }
      delay(200);
    }
    switch (DyWeek) {
      case 1: display.print("Sunday");break;
      case 2: display.print("Monday");break;
      case 3: display.print("Tuesday");break;
      case 4: display.print("Wednesday");break;
      case 5: display.print("Thursday");break;
      case 6: display.print("Friday");break;
      case 7: display.print("Sarurday");break;
    } display.display();
  }

my case is when executing this custom function my Arduino was restarting automatically. I tried lot of times but Its could find error. previous custom function designed to change month, is same like this but its working correctly.

  if (subframe == 2) {
    display.setCursor(0, 0);
    display.print("Set Month");
    display.setCursor(0, 10);
    display.print(">>> ");
    display.display();
    if (digitalRead(btnChange) == LOW) {
      M++;
      if (M == 13) {
        M = 1;
      }
      delay(200);
    }
    switch (M) {
      case 1: display.print("January");break;
      case 2: display.print("February");break;
      case 3: display.print("March");break;
      case 4: display.print("April");break;
      case 5: display.print("May");break;
      case 6: display.print("June");break;
      case 7: display.print("July ");break;
      case 8: display.print("August");break;
      case 9: display.print("September");break;
      case 10: display.print("October");break;
      case 11: display.print("November");break;
      case 12: display.print("December");break;
    } display.display();
  }

This is working correctly, but previous function will restarts my Arduino automatically. I cant find mistakes. so guys need your help to fix this problem.
Thank You.

Show a complete code that is compilable and just enough to reproduce the problem

And, this isn’t logical :

DyWeek++;
if (DyWeek < 8) {
  DyWeek = 1;
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.