Beginner making a complex/modular alarm clock

hey guys, aside from breakbeam triggers and turning things on with the ambient light, this is my first project. feels like i'm getting close but i can't seem to figure out what i'm doing wrong

#include <DS3231.h>
#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
const int blue= 13;  //
const int green= 12;
const int yellow= 10;
const int white= 9;
const int red= 8;
const int blueSTATE = 0;
const int greenSTATE = 0;
const int yellowSTATE = 0;
const int whiteSTATE = 0;
const int redSTATE = 0;
#define time now = time_t(1740942204);

 
DS3231 Clock;

byte year;
byte month;
byte date;
byte dOW;
byte hour;
byte minute;
byte second;
byte temperature;

void getDateStuff(byte& year, byte& month, byte& date, byte& dOW,
                  byte& hour, byte& minute, byte& second, byte& temperature) {
    // Call this if you notice something coming in on
    // the serial port. The stuff coming in should be in
    // the order YYMMDDwHHMMSS, with an 'x' at the end.
    boolean gotString = false;
    char inChar;
    byte temp1, temp2;
    char inString[20];
    
    byte j=0;
    while (!gotString) {
        if (Serial.available()) {
            inChar = Serial.read();
            inString[j] = inChar;
            j += 1;
            if (inChar == 'x') {
                gotString = true;
            }
        }
    }
    Serial.println(inString);
    // Read year first
    temp1 = (byte)inString[0] -48;
    temp2 = (byte)inString[1] -48;
    year = temp1*10 + temp2;
    // now month
    temp1 = (byte)inString[2] -48;
    temp2 = (byte)inString[3] -48;
    month = temp1*10 + temp2;
    // now date
    temp1 = (byte)inString[4] -48;
    temp2 = (byte)inString[5] -48;
    date = temp1*10 + temp2;
    // now Day of Week
    dOW = (byte)inString[6] - 48;
    // now hour
    temp1 = (byte)inString[7] -48;
    temp2 = (byte)inString[8] -48;
    hour = temp1*10 + temp2;
    // now minute
    temp1 = (byte)inString[9] -48;
    temp2 = (byte)inString[10] -48;
    minute = temp1*10 + temp2;
    // now second
    temp1 = (byte)inString[11] -48;
    temp2 = (byte)inString[12] -48;
    second = temp1*10 + temp2;
}

String comdata ="";
const int numdata[7] = {0},mark = 0;
const int buzz = 11;




void setup() {

pinMode(blue, INPUT_PULLUP);
pinMode(green, INPUT_PULLUP);
pinMode(yellow, INPUT_PULLUP);
pinMode(white, INPUT_PULLUP);
pinMode(red, INPUT_PULLUP);
pinMode(buzz, OUTPUT);
  Wire.begin();
  Serial.begin(9600);
// set up the LCD's number of columns and rows:
  lcd.begin(16,2);
// Print a message to the LCD.
  lcd.print("  DEEZ ");
  lcd.setCursor(0,1);  //Display position
  lcd.print("        NUTZ");
   delay(2000);
  lcd.clear();   
   
  
 }

void loop() {

    
    // If something is coming in on the serial line, it's
    // a time correction so set the clock accordingly.
    if (Serial.available());
      
        getDateStuff(year, month, date, dOW, hour, minute, second, temperature);
        
        Clock.setClockMode(false);  // set to 24h
        //setClockMode(true); // set to 12h
        
        Clock.setYear(year);
        Clock.setMonth(month);
        Clock.setDate(date);
        Clock.setDoW(dOW);
        Clock.setHour(hour);
        Clock.setMinute(minute);
        Clock.setSecond(second);
}
void WriteDS3231();
  {
  Clock.setSecond(numdata[6]); 
  Clock.setMinute(numdata[5]); 
  Clock.setHour(numdata[4]);   
  Clock.setDoW(numdata[3]);    
  Clock.setDate(numdata[2]);   
  Clock.setMonth(numdata[1]);  
  Clock.setYear(numdata[0]);
 } 




   void Print_time();
   {
  
  
    Clock.getTemperature();
    lcd.setCursor(0, 0);
    lcd.print("20");  // Show 20 Century
    if (year>=10)    // Display year
      {
      lcd.print(year,DEC);
      }
      else
      {
      lcd.print("0");
      lcd.print(year,DEC);
      }
    lcd.print('-');
    }
    lcd.setCursor(5, 0);
    if (month>=10)  //Display month 
      {
      lcd.print(month,DEC);
      }
      else
      {
      lcd.print("0");
      lcd.print(month,DEC);
      }
  lcd.print('-');

  lcd.setCursor(8, 0);
    if (date>=10)  // Display date
      {
      lcd.print(date,DEC);
      }
      else
      {
      lcd.print("0");
      lcd.print(date,DEC);
      }

  lcd.setCursor(11, 0);
    switch (dOW)  // Display Week
      {
      case 1:  // When Dow is equal to 1, execute the following statement
        lcd.print("Mon");
        break;
      case 2:  // When Dow is equal to 2, execute the following statement
        lcd.print("Tue");
        break;
      case 3:
        lcd.print("Wed");
        break;
      case 4:
        lcd.print("Thu");
        break;
      case 5:
        lcd.print("Fri");
        break;
      case 6:
        lcd.print("Sat");
        break;
      case 7:
        lcd.print("Sun");
        break;
      }

  lcd.setCursor(0, 1);//Move the cursor to the second line.
    if (hour>=10)     //Display hours
      {
      lcd.print(hour,DEC);
      }
      else
      {
      lcd.print("0");
      lcd.print(hour,DEC);
      }
  lcd.print(':');

  lcd.setCursor(3, 1);
    if (minute>=10)  // Display minutes
      {
      lcd.print(minute,DEC);
      }
      else
      {
      lcd.print("0");
      lcd.print(minute,DEC);
      }
  lcd.print(':');

  lcd.setCursor(6, 1);
    if (second>=10)  //Display seconds
      {
      lcd.print(second,DEC);
      }
      else
      {
      lcd.print("0");
      lcd.print(second,DEC);
      }

      lcd.setCursor(12, 1);
      lcd.print(temperature);  // Display temperature
      lcd.write(0xdf);         // Display temperature symbol
      lcd.print("C");
      }   

      if( hour == 7 &&  (minute == 30 || minute == 35)); //Comparing the current time with the Alarm time
 
     {
     tone(buzz, 50);
     delay(50);
     noTone(buzz);
     delay(100);  
     lcd.clear();
     lcd.print("WAKE THE");
     lcd.setCursor(0,1);
     lcd.print("FUCK UP");
      delay(1000);
     }

    
      
   

Now keep in mind it's incomplete, but kinda feels like i gotta fix this now before continuing.

my current serial output is;

C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:129:3: error: expected unqualified-id before '{' token
   {
   ^
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:143:4: error: expected unqualified-id before '{' token
    {
    ^
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:160:5: error: 'lcd' does not name a type
     lcd.setCursor(5, 0);
     ^~~
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:161:5: error: expected unqualified-id before 'if'
     if (month>=10)  //Display month
     ^~
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:165:7: error: expected unqualified-id before 'else'
       else
       ^~~~
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:170:3: error: 'lcd' does not name a type
   lcd.print('-');
   ^~~
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:172:3: error: 'lcd' does not name a type
   lcd.setCursor(8, 0);
   ^~~
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:173:5: error: expected unqualified-id before 'if'
     if (date>=10)  // Display date
     ^~
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:177:7: error: expected unqualified-id before 'else'
       else
       ^~~~
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:183:3: error: 'lcd' does not name a type
   lcd.setCursor(11, 0);
   ^~~
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:184:5: error: expected unqualified-id before 'switch'
     switch (dOW)  // Display Week
     ^~~~~~
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:209:3: error: 'lcd' does not name a type
   lcd.setCursor(0, 1);//Move the cursor to the second line.
   ^~~
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:210:5: error: expected unqualified-id before 'if'
     if (hour>=10)     //Display hours
     ^~
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:214:7: error: expected unqualified-id before 'else'
       else
       ^~~~
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:219:3: error: 'lcd' does not name a type
   lcd.print(':');
   ^~~
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:221:3: error: 'lcd' does not name a type
   lcd.setCursor(3, 1);
   ^~~
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:222:5: error: expected unqualified-id before 'if'
     if (minute>=10)  // Display minutes
     ^~
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:226:7: error: expected unqualified-id before 'else'
       else
       ^~~~
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:231:3: error: 'lcd' does not name a type
   lcd.print(':');
   ^~~
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:233:3: error: 'lcd' does not name a type
   lcd.setCursor(6, 1);
   ^~~
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:234:5: error: expected unqualified-id before 'if'
     if (second>=10)  //Display seconds
     ^~
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:238:7: error: expected unqualified-id before 'else'
       else
       ^~~~
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:244:7: error: 'lcd' does not name a type
       lcd.setCursor(12, 1);
       ^~~
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:245:7: error: 'lcd' does not name a type
       lcd.print(temperature);  // Display temperature
       ^~~
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:246:7: error: 'lcd' does not name a type
       lcd.write(0xdf);         // Display temperature symbol
       ^~~
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:247:7: error: 'lcd' does not name a type
       lcd.print("C");
       ^~~
C:\Users\Jucifer\Documents\Arduino\Alarm_clock_Project\Alarm_clock_Project.ino:248:7: error: expected declaration before '}' token
       }
       ^

exit status 1

Compilation error: expected unqualified-id before '{' token

things left to be added
set alarm time (pin red)
stop button (pin white)
value + (yellow)
value - (green)
set time/next value (blue)
and i was thinking a tilt switch for snooze or just another button.

You have about four errors. A lot is due to poor coding style. Use Tools/Auto Format for starters. CLUE code outside a function will cause errors nearby.
I spent 3 mins and got a clean compile.
BTW, when you fix the first {} error, do another Auto Format, rinse repeat.

ha, didnt even know auto format was a thing, thanks

It isn't just a way of having a 'standard' formatting, in this case it will show you the error.

for inspiration and code snippets

decided to change my board and display, going with a RP Pico 2w and a 128x32 oled display.
Also updated the code. i can have it compile but wont go past the setup

#include <RTClib.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
Adafruit_SSD1306 display(128, 32);
RTC_DS3231 RTC;

//************Button*****************//
int P1 = 3;  // Button SET MENU'
int P2 = 1;  // Button +
int P3 = 0;  // Button -
int P4 = 2;  // SWITCH Alarm

//**************Alarm***************//
#define LED 28
#define buzzer 6

//************Variables**************//
int hourupg;
int minupg;
int yearupg;
int monthupg;
int dayupg;
int menu = 0;
int setAll = 0;


uint8_t alarmHours = 7, alarmMinutes = 30;  // Holds the current alarm time


void setup() { 
  Wire.begin();

  Serial.begin(9600);

  RTC.begin();

  pinMode(P1, INPUT_PULLUP);
  pinMode(P2, INPUT_PULLUP);
  pinMode(P3, INPUT_PULLUP);
  pinMode(P4, INPUT_PULLUP);
  Serial.begin(115200);

  pinMode(buzzer, OUTPUT);
  // Initialize the display
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // Address 0x3C for 128x32

  pinMode(LED, OUTPUT);

  // Clear the display
  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(1);
  display.setCursor(0, 1);
  display.println("lygma  deez");
  display.println("balls    nutz");
  display.display();  
  delay(1000);
  
  

  if (!RTC.lostPower()) {
    Serial.println("RTC is NOT running!");
    // Set the date and time at compile time
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
  // RTC.adjust(DateTime(__DATE__, __TIME__)); //removing "//" to adjust the time
  // The default display shows the date and time
  int menu = 0;
  
}

void loop() {

  // check if you press the SET button and increase the menu index
  if (digitalRead(P1) == LOW) {
    menu = menu + 1;
  }
  if ((digitalRead(P2) == LOW) && (digitalRead(P3) == LOW)) {
    

    DisplaySetHourAll();
    DisplaySetMinuteAll();
    display.clearDisplay();
    display.setTextColor(WHITE);
    display.setTextSize(1);
    display.setCursor(0, 1);
    display.print("ALARM");
    display.setCursor(0, 1);
    display.println(alarmHours, DEC);
    display.println(":");
    display.println(alarmMinutes, DEC);
    delay(1000);
    display.clearDisplay();
  }
  // in which subroutine should we go?
  if (menu == 0) {
    DisplayDateTime();  // void DisplayDateTime
    Alarm();            // Alarm control
  }
  if (menu == 1) {
    DisplaySetHour();
  }
  if (menu == 2) {
    DisplaySetMinute();
  }
  if (menu == 3) {
    DisplaySetYear();
  }
  if (menu == 4) {
    DisplaySetMonth();
  }
  if (menu == 5) {
    DisplaySetDay();
  }
  if (menu == 6) {
    StoreAgg();
    delay(500);
    menu = 0;
  }
  delay(100);
}

void DisplayDateTime() {
  // We show the current date and time
  DateTime now = RTC.now();
  display.setTextColor(WHITE);
  display.setTextSize(1);
  display.setCursor(0, 2);
  display.print("Hour : ");

  if (now.hour() <= 9) {
    display.print("0");
  }
  display.print(now.hour(), DEC);
  hourupg = now.hour();
  display.print(":");
  if (now.minute() <= 9) {
    display.print("0");
  }
  display.print(now.minute(), DEC);
  minupg = now.minute();
  display.print(":");
  if (now.second() <= 9) {
    display.print("0");
  }
  display.print(now.second(), DEC);


  display.setCursor(0, 1);
  display.print("Date : ");
  if (now.day() <= 9) {
    display.print("0");
  }
  display.print(now.day(), DEC);
  dayupg = now.day();
  display.print("/");
  if (now.month() <= 9) {
    display.print("0");
  }
  display.print(now.month(), DEC);
  monthupg = now.month();
  display.print("/");
  display.print(now.year(), DEC);
  yearupg = now.year();

  char DOW[][10] = { "Sunday   ", "Monday   ", "Tuesday  ", "Wednesday", "Thursday ", "Friday   ", "Saturday " };
  display.setCursor(0, 0);
  display.print("Day  : ");
  display.print(DOW[now.dayOfTheWeek()]);  // if it appears error in the code, enter the code given below
  //display.print(DOW[now.dayOfWeek()]);
}

void DisplaySetHour() {
  // time setting
  display.clearDisplay();
  DateTime now = RTC.now();
  if (digitalRead(P2) == LOW) {
    if (hourupg == 23) {
      hourupg = 0;
    } else {
      hourupg = hourupg + 1;
    }
  }
  if (digitalRead(P3) == LOW) {
    if (hourupg == 0) {
      hourupg = 23;
    } else {
      hourupg = hourupg - 1;
    }
  }
  display.setCursor(0, 0);
  display.print("Set time:");
  display.setCursor(0, 1);
  display.print(hourupg, DEC);
  delay(200);
}

void DisplaySetMinute() {
  // Setting the minutes
  display.clearDisplay();
  if (digitalRead(P2) == LOW) {
    if (minupg == 59) {
      minupg = 0;
    } else {
      minupg = minupg + 1;
    }
  }
  if (digitalRead(P3) == LOW) {
    if (minupg == 0) {
      minupg = 59;
    } else {
      minupg = minupg - 1;
    }
  }
  display.setCursor(0, 0);
  display.print("Set Minutes:");
  display.setCursor(0, 1);
  display.print(minupg, DEC);
  delay(200);
}

void DisplaySetYear() {
  // setting the year
  display.clearDisplay();
  if (digitalRead(P2) == LOW) {
    yearupg = yearupg + 1;
  }
  if (digitalRead(P3) == LOW) {
    yearupg = yearupg - 1;
  }
  display.setCursor(0, 0);
  display.print("Set Year:");
  display.setCursor(0, 1);
  display.print(yearupg, DEC);
  delay(200);
}

void DisplaySetMonth() {
  // Setting the month
  display.clearDisplay();
  if (digitalRead(P2) == LOW) {
    if (monthupg == 12) {
      monthupg = 1;
    } else {
      monthupg = monthupg + 1;
    }
  }
  if (digitalRead(P3) == LOW) {
    if (monthupg == 1) {
      monthupg = 12;
    } else {
      monthupg = monthupg - 1;
    }
  }
  display.setCursor(0, 0);
  display.print("Set Month:");
  display.setCursor(0, 1);
  display.print(monthupg, DEC);
  delay(200);
}

void DisplaySetDay() {
  // Setting the day
  display.clearDisplay();
  if (digitalRead(P2) == LOW) {
    if (dayupg == 31) {
      dayupg = 1;
    } else {
      dayupg = dayupg + 1;
    }
  }
  if (digitalRead(P3) == LOW) {
    if (dayupg == 1) {
      dayupg = 31;
    } else {
      dayupg = dayupg - 1;
    }
  }
  display.setCursor(0, 0);
  display.print("Set Day:");
  display.setCursor(0, 1);
  display.print(dayupg, DEC);
  delay(200);
}

void StoreAgg() {
  // Variable saving
  display.clearDisplay();
  display.setCursor(0, 0);
  display.print("SAVING IN");
  display.setCursor(0, 1);
  display.print("PROGRESS");
  RTC.adjust(DateTime(yearupg, monthupg, dayupg, hourupg, minupg, 0));
  delay(200);
}
void DisplaySetHourAll()  // Setting the alarm minutes
{
  while (digitalRead(P1) == HIGH) {

    display.clearDisplay();

    if (digitalRead(P2) == LOW) {
      if (alarmHours == 23) {
        alarmHours = 0;
      } else {
        alarmHours = alarmHours + 1;
      }
    }
    if (digitalRead(P3) == LOW) {
      if (alarmHours == 0) {
        alarmHours = 23;
      } else {
        alarmHours = alarmHours - 1;
      }
    }
    display.setCursor(0, 0);
    display.print("Set HOUR Alarm:");
    display.setCursor(0, 1);
    display.print(alarmHours, DEC);
    delay(200);
  }
  delay(200);
}

void DisplaySetMinuteAll()  // Setting the alarm minutes
{
  while (digitalRead(P1) == HIGH) {

    display.clearDisplay();
    if (digitalRead(P2) == LOW) {
      if (alarmMinutes == 59) {
        alarmMinutes = 0;
      } else {
        alarmMinutes = alarmMinutes + 1;
      }
    }
    if (digitalRead(P3) == LOW) {
      if (alarmMinutes == 0) {
        alarmMinutes = 59;
      } else {
        alarmMinutes = alarmMinutes - 1;
      }
    }
    display.setCursor(0, 0);
    display.print("Set MIN. Alarm:");
    display.setCursor(0, 1);
    display.print(alarmMinutes, DEC);
    delay(200);
  }
  delay(200);
}
void printAllOn() {
  display.setCursor(0, 0);
  display.print("Alarm: ");



  if (alarmHours <= 9) {
    display.print("0");
  }
  display.print(alarmHours, DEC);

  display.print(":");
  if (alarmMinutes <= 9) {
    display.print("0");
  }
  display.print(alarmMinutes, DEC);
}
void printAllOff() {
  display.setCursor(0, 1);
  display.print("Alarm: Off  ");
}
void Alarm() {
  if (digitalRead(P4) == LOW) {
    setAll = setAll + 1;
  }
  if (setAll == 0) {
    printAllOff();
    noTone(buzzer);
    digitalWrite(LED, LOW);
  }
  if (setAll == 1) {

    printAllOn();    
  
     DateTime now = RTC.now();
     if ( now.hour() == alarmHours && now.minute() == alarmMinutes )
        {
         
         DateTime now = RTC.now();
         digitalWrite(LED,HIGH);
         tone(buzzer,880); //play the note "A5" (LA5)
         delay (300);
         tone(buzzer,698); //play the note "F6" (FA5)
         
        }
    else{
         noTone (buzzer);
         digitalWrite(LED,LOW);
        }
    
    } 
  if (setAll==2)
    {
     setAll=0;
    }
    delay(200);
}

once i get this working, i d plan on using this to automate some stuff around the house (fish tank lights, turn on coffee maker....)

figured i'd give an update.
went back to using an arduino R3.
Almost have it working, I think it's an I2C conflict but not sure what i should do to resolve it.
currently connected using 2 sets of pins, the time isnt "flowing" and characters sometimes change spaces.

here's the updated code

#include "RTClib.h"
#include <wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_W 128
#define SCREEN_H 32
#define OLED_RESET  -1 
#define SCREEN_ADDRESS 0x3C
RTC_DS3231 rtc;
DateTime now;
Adafruit_SSD1306 display(SCREEN_W, SCREEN_H, &Wire);

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

//************Variables**************//
int hourupg;
int minupg;
int yearupg;
int monthupg;
int dayupg;
int menu = 0;
int setAll = 0;

//************Button*****************//
int P1 = 12;  // Button SET MENU'
int P2 = 10;  // Button +
int P3 = 9;   // Button -
int P4 = 11;  // SWITCH Alarm

//**************Alarm***************//
#define LED 7
#define buzzer 6



uint8_t alarmHours = 7, alarmMinutes = 30;  // Holds the current alarm time

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Wire.begin(0x3C);
  Wire.begin(0x57);
  Wire.begin(0x68);
  

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;)
      ;  // Don't proceed, loop forever
  }
/*
#ifndef ATmega328
  while (!Serial)
    ;  // wait for serial port to connect. Needed for native USB
#endif
*/

  if (!rtc.begin()) {
    Serial.println("Couldn't find rtc");
    //Serial.flush();
    while (1) delay(10);
  }

  if (rtc.lostPower()) {
    Serial.println("rtc lost power, let's set the time!");
  }
}
void loop() {
  // check if you press the SET button and increase the menu index
  if (digitalRead(P1) == LOW) {
    menu = menu + 1;
  }
  if ((digitalRead(P2) == LOW) && (digitalRead(P3) == LOW)) {


    display.clearDisplay();
    display.setTextColor(WHITE);
    display.setTextSize(1);
    display.setCursor(0, 10);
    display.print("ALARM");
    display.setCursor(0, 10);
    display.println(alarmHours, DEC);
    display.println(":");
    display.println(alarmMinutes, DEC);
    //delay(0);
    display.clearDisplay();
  }
  // in which subroutine should we go?
  if (menu == 0) {
    DisplayDateTime();  // void DisplayDateTime
    Alarm();            // Alarm control
  }
  if (menu == 1) {
    DisplaySetHour();
  }
  if (menu == 2) {
    DisplaySetMinute();
  }
  if (menu == 3) {
    DisplaySetYear();
  }
  if (menu == 4) {
    DisplaySetMonth();
  }
  if (menu == 5) {
    DisplaySetDay();
  }
  if (menu == 6) {
    StoreAgg();
    delay(500);
    menu = 0;
  }
  millis();
  //delay(100);
  // put your main code here, to run repeatedly:
  // display.clearDisplay();
  //delay(0);
}



void DisplayDateTime() {
  // We show the current date and time
  DateTime now = rtc.now();
  
  
  display.clearDisplay();

  display.setTextColor(SSD1306_WHITE);
  display.setTextSize(1);
  display.print("");

  if (now.hour() <= 9) {
    display.setCursor(0, 13);
    display.print("0");
  }
  display.setCursor(5, 13);
  display.println(now.hour(), DEC);
  hourupg = now.hour();
  display.print("");
  if (now.minute() <= 9) {
    display.setCursor(30, 13);
    display.print("0");
  }
  display.setCursor(11, 13);
  display.println(now.minute(), DEC);
  minupg = now.minute();
  display.print("");
  if (now.second() <= 9) {
    display.setCursor(16, 13);
    display.print("0");
  }
  display.setCursor(22, 13);
  display.println(now.second(), DEC);

  display.setTextSize(1);
  display.setCursor(27, 0);
  display.print("");
  if (now.day() <= 9) {
    display.setCursor(32, 0);
    display.print("0");
  }
  display.setCursor(65, 0);
  display.println(now.day(), DEC);
  dayupg = now.day();
  display.print("");
  if (now.month() <= 9) {
    display.setCursor(50, 0);
    display.print("0");
  }
  display.setCursor(55, 0);
  display.println(now.month(), DEC);
  monthupg = now.month();
  display.print("");
  display.setCursor(88, 0);
  display.println(now.year(), DEC);
  yearupg = now.year();

  char DOW[][10] = { "Sunday   ", "Monday   ", "Tuesday  ", "Wednesday", "Thursday ", "Friday   ", "Saturday " };
  display.setCursor(0, 0);
  display.print("");
  display.println(DOW[now.dayOfTheWeek()]);  // if it appears error in the code, enter the code given below
  //display.print(DOW[now.dayOfWeek()]);
  display.display(); 
  /*
char buf1[20];
//Updated now.day to now.date
sprintf(buf1, "%02d:%02d:%02d %02d/%02d/%02d",  now.hour(), now.minute(), now.second(), now.day(), now.month(), now.year()); 

display.clearDisplay();
display.setCursor(0, 25);
display.setTextSize(2);
display.print(F("Date/Time: "));
Serial.println(buf1);
delay(0);
  */
}

void DisplaySetHour() {
  // time setting
  display.clearDisplay();
  DateTime now = rtc.now();
  if (digitalRead(P2) == LOW) {
    if (hourupg == 23) {
      hourupg = 0;
    } else {
      hourupg = hourupg + 1;
    }
  }
  if (digitalRead(P3) == LOW) {
    if (hourupg == 0) {
      hourupg = 23;
    } else {
      hourupg = hourupg - 1;
    }
  }
  display.setCursor(0, 0);
  display.print("Set time:");
  display.setCursor(30, 0);
  display.print(hourupg, DEC);
  delay(200);
}

void DisplaySetMinute() {
  // Setting the minutes
  display.clearDisplay();
  if (digitalRead(P2) == LOW) {
    if (minupg == 59) {
      minupg = 0;
    } else {
      minupg = minupg + 1;
    }
  }
  if (digitalRead(P3) == LOW) {
    if (minupg == 0) {
      minupg = 59;
    } else {
      minupg = minupg - 1;
    }
  }
  display.setCursor(0, 10);
  display.print("Set Minutes:");
  display.setCursor(0, 10);
  display.print(minupg, DEC);
  delay(200);
}

void DisplaySetYear() {
  // setting the year
  display.clearDisplay();
  if (digitalRead(P2) == LOW) {
    yearupg = yearupg + 1;
  }
  if (digitalRead(P3) == LOW) {
    yearupg = yearupg - 1;
  }
  display.setCursor(0, 10);
  display.print("Set Year:");
  display.setCursor(0, 10);
  display.print(yearupg, DEC);
  delay(200);
}

void DisplaySetMonth() {
  // Setting the month
  display.clearDisplay();
  if (digitalRead(P2) == LOW) {
    if (monthupg == 12) {
      monthupg = 1;
    } else {
      monthupg = monthupg + 1;
    }
  }
  if (digitalRead(P3) == LOW) {
    if (monthupg == 1) {
      monthupg = 12;
    } else {
      monthupg = monthupg - 1;
    }
  }
  display.setCursor(0, 10);
  display.print("Set Month:");
  display.setCursor(0, 10);
  display.print(monthupg, DEC);
  delay(200);
}

void DisplaySetDay() {
  // Setting the day
  display.clearDisplay();
  if (digitalRead(P2) == LOW) {
    if (dayupg == 31) {
      dayupg = 1;
    } else {
      dayupg = dayupg + 1;
    }
  }
  if (digitalRead(P3) == LOW) {
    if (dayupg == 1) {
      dayupg = 31;
    } else {
      dayupg = dayupg - 1;
    }
  }
  display.setCursor(0, 10);
  display.print("Set Day:");
  display.setCursor(0, 10);
  display.print(dayupg, DEC);
  delay(200);
}

void StoreAgg() {
  // Variable saving
  display.clearDisplay();
  display.setCursor(0, 10);
  display.print("SAVING IN");
  display.setCursor(0, 10);
  display.print("PROGRESS");
  rtc.adjust(DateTime(yearupg, monthupg, dayupg, hourupg, minupg, 0));
  delay(200);
}
void DisplaySetHourAll()  // Setting the alarm minutes
{
  while (digitalRead(P1) == HIGH) {

    display.clearDisplay();

    if (digitalRead(P2) == LOW) {
      if (alarmHours == 23) {
        alarmHours = 0;
      } else {
        alarmHours = alarmHours + 1;
      }
    }
    if (digitalRead(P3) == LOW) {
      if (alarmHours == 0) {
        alarmHours = 23;
      } else {
        alarmHours = alarmHours - 1;
      }
    }
    display.setCursor(0, 10);
    display.print("Set HOUR Alarm:");
    display.setCursor(0, 10);
    display.print(alarmHours, DEC);
    delay(200);
  }
  delay(200);
}

void DisplaySetMinuteAll()  // Setting the alarm minutes
{
  while (digitalRead(P1) == HIGH) {

    display.clearDisplay();
    if (digitalRead(P2) == LOW) {
      if (alarmMinutes == 59) {
        alarmMinutes = 0;
      } else {
        alarmMinutes = alarmMinutes + 1;
      }
    }
    if (digitalRead(P3) == LOW) {
      if (alarmMinutes == 0) {
        alarmMinutes = 59;
      } else {
        alarmMinutes = alarmMinutes - 1;
      }
    }
    display.setCursor(0, 10);
    display.print("Set MIN. Alarm:");
    display.setCursor(0, 10);
    display.print(alarmMinutes, DEC);
    delay(200);
  }
  delay(200);
}
void printAllOn() {
  display.setCursor(0, 10);
  display.print("Alarm: ");



  if (alarmHours <= 9) {
    display.print("0");
  }
  display.print(alarmHours, DEC);

  display.print(":");
  if (alarmMinutes <= 9) {
    display.print("0");
  }
  display.print(alarmMinutes, DEC);
}
void printAllOff() {
  display.setCursor(0, 10);
  display.print("Alarm: Off  ");
}
void Alarm() {
  if (digitalRead(P4) == LOW) {
    setAll = setAll + 1;
  }
  if (setAll == 0) {
    printAllOff();
    noTone(buzzer);
    digitalWrite(LED, LOW);
  }
  if (setAll == 1) {

    printAllOn();

    DateTime now = rtc.now();
    if (now.hour() == alarmHours && now.minute() == alarmMinutes) {

      DateTime now = rtc.now();
      digitalWrite(LED, HIGH);
      tone(buzzer, 880);  //play the note "A5" (LA5)
      delay(300);
      tone(buzzer, 698);  //play the note "F6" (FA5)

    } else {
      noTone(buzzer);
      digitalWrite(LED, LOW);
    }
  }
  if (setAll == 2) {
    setAll = 0;
  }
  delay(200);
}

I want to thank you guys for the help.

finally got it all working. the board is almost at its limit, and it was a nice learning experience.

only works as an alarm for now and i doubt il be able to use it for more than an alarm clock unless i switch to another board.

You cold store these character arrays using PROGMEM to free some memory, then display.print(); the array when needed.

1 Like