Help alarm clock settings

I'm trying to make something like an alarm clock. But i'm having troubles on setting the time 2 times. It works without any problem with one but now that i added another setTime it won't work. As i test it out, i realized that it skipped the another setTime and goes immediately to printTime. I figured that it maybe because the values stored in my "ch1" & "cm1" is also being stored in my "ch2" & "cm2." I need help on how to fix it. Apologies as my program is really messy. I would really appreciate any help, thanks in advance.

void loop

void loop()
{
  setTime();
  
  if(val3 != HIGH); 
  {  
    ch1 = counter1;
    cm1 = counter2;

    setTime();
  }
    
    if(val3 != HIGH);
    {
      ch2 = counter1;
      cm2 = counter2;
    } 
    
     do
      {
      lcd.clear();
      printTime();
      }
      while((clock.hour != ch1)||(clock.minute != cm1)); // Use OR logic because of the "!=" logic.
      
      do
       {
        timeup();
       }
       while(val3 != HIGH);

         do
         {
           loopswitch3();
           digitalWrite(led1,LOW);
           noTone;
           val2= digitalRead(switchPin2);
         }
         while (val2 != HIGH);
       
           do
            {
              lcd.clear();
              printTime();
            }
            while((clock.hour != ch2)||(clock.minute != cm2));
       
              do
               {
                timeup();
               }
               while(val3 != HIGH);
         
                 loopswitch3();
               
                 if(val3 >= 2);
                 
                 do
                 {
                   timeup();
                   
                 }while(val3 != HIGH);                  
                   
}

setTime();

void setTime()
{
    lcd.setCursor(0, 0); //top,left  
    lcd.setCursor(0, 0); 
    lcd.print("Set time for c1k");
      
    loopswitch1();
    loopswitch2();

    lcd.setCursor(0, 2); //bottom,left
    lcd.print("   ");     
    lcd.setCursor(0, 2); 
    lcd.print(counter1);
      
    lcd.setCursor(2, 2); // bottom,2 rows to the right
    lcd.print(":");
      
    lcd.setCursor(3, 2); // bottom,3 rows to the right
    lcd.print("   ");     
    lcd.setCursor(3, 2); 
    lcd.print(counter2);
    val3= digitalRead(switchPin3);
}

Suggestion: Go back to working code. Create a real flowchart. Remember, the uC is fast enough that you can complete some logic tests and move on in code before a switch has time to open.

Ray

Hi, sorry but i'm really loss at the moment. I don't see much difference with the working one and this program. Is it because of the flow of the program?

Tell us what you want your sketch to do.

Always show us your complete sketch.

Working code

#include <LiquidCrystal.h>
#include "pitches.h"
#include <Wire.h>
#include "DS1307.h"
#include <time.h>

void loopswitch1(void);
void loopswitch2(void);
void loopswitch3(void);
void loopsound(void);
void printTime(void);
void setupTime(void);
void setTime(void);
void timeup(void);
void blinklight(void);

LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );

int switchPin1 =48; // choose the input pin (for a pushbutton)
int val1 = 0; // variable for reading the pin status
int counter1 = 0;
int currentState1 = 0;
int previousState1 = 0;

int switchPin2 =49; // choose the input pin (for a pushbutton)
int val2 = 0; // variable for reading the pin status
int counter2 = 0;
int currentState2 = 0;
int previousState2 = 0;

int switchPin3 =50; // choose the input pin (for a pushbutton)
int val3 = 0; // variable for reading the pin status
int counter3 = 0;
int currentState3 = 0;
int previousState3 = 0;
int currenstate = 0;

int ch1 = 0;
int cm1 = 0;
int ch2 = 0;
int cm2 = 0;

int led = 28;

int act = 26;

int speakerOut = 44;  

int melody[] = {
  NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  4, 8, 8, 4,4,4,4,4 };

DS1307 clock;//define a object of DS1307 class

void setup() 
{
  Serial.begin(9600);
  lcd.begin(16, 2);  //no. of columns x rows
  pinMode(switchPin1, INPUT); // declare pushbutton as input
  setupTime();
  pinMode( led, OUTPUT);

}

void loop()
{
  setTime();

  do
  {
    lcd.clear();
    //lcd.setCursor(0, 0); //top,left  
    // lcd.setCursor(0, 0); 
    printTime();

  }
  while((clock.hour != ch1)||(clock.minute != cm1)); // Use OR logic because of the "!=" logic.

  timeup();

  return;
}


//========================================

void setupTime()
{
  clock.begin();
  clock.fillByYMD(2013,7,24);//Jan 19,2013
  clock.fillByHMS(1,1,45);//15:28 30"
  clock.fillDayOfWeek(SUN);//Saturday
  clock.setTime();//write time to the RTC chip
}
void printTime()
{
  clock.getTime();
  lcd.setCursor(0, 0); //bottom,left
  lcd.print("  ");     
  lcd.setCursor(0, 0); 
  lcd.print(clock.hour, DEC);

  lcd.setCursor(2, 0); // bottom,2 rows to the right
  lcd.print(":");

  lcd.setCursor(3, 0); //bottom,left
  lcd.print("  ");     
  lcd.setCursor(3, 0); 
  lcd.print(clock.minute, DEC);

  lcd.setCursor(5, 0); // bottom,2 rows to the right
  lcd.print(":");

  lcd.setCursor(6, 0); //bottom,left
  lcd.print("  ");     
  lcd.setCursor(6, 0); 
  lcd.print(clock.second, DEC);

  lcd.setCursor(0, 2); //bottom,left
  lcd.print("  ");     
  lcd.setCursor(0, 2); 
  lcd.print(clock.month, DEC);

  lcd.setCursor(2, 2); // bottom,2 rows to the right
  lcd.print("/");

  lcd.setCursor(3, 2); //bottom,left
  lcd.print("  ");     
  lcd.setCursor(3, 2); 
  lcd.print(clock.dayOfMonth, DEC);

  lcd.setCursor(5, 2); // bottom,2 rows to the right
  lcd.print("/");

  lcd.setCursor(6, 2); //bottom,left
  lcd.print("  ");     
  lcd.setCursor(6, 2); 
  lcd.print(clock.year+2000, DEC);
  lcd.print("  ");

  switch (clock.dayOfWeek)
  {
  case MON:
    lcd.print("MON");
    break;
  case TUE:
    lcd.print("TUE");
    break;
  case WED:
    lcd.print("WED");
    break;
  case THU:
    lcd.print("THU");
    break;
  case FRI:
    lcd.print("FRI");
    break;
  case SAT:
    lcd.print("SAT");
    break;
  case SUN:
    lcd.print("SUN");
    break;
  }
  delay(1000);
}
//=========================================

void loopswitch1()
{
  val1 = digitalRead(switchPin1); // read input value

  if (val1 == HIGH) 
  { // check if the input is HIGH (button released)
    currentState1 = 1;
  }
  else 
  {
    currentState1 = 0;
  }

  if(currentState1 != previousState1)
  {
    if(currentState1 == 1)
    {
      counter1 = counter1 + 1;

      if(counter1 == 25)
      {
        counter1 = counter1 - 24;
      }

      //Serial.print("\b\b"); 
      //Serial.print(counter1);
    }
  }

  previousState1 = currentState1;

  //  delay(50);
}

//=====================================

void loopswitch2()
{
  pinMode(switchPin2, INPUT);
  val2 = digitalRead(switchPin2); // read input value
  if (val2 == HIGH) 
  { // check if the input is HIGH (button released)
    currentState2 = 1;
  }
  else 
  {
    currentState2 = 0;
  }
  if(currentState2 != previousState2)
  {
    if(currentState2 == 1)
    {
      counter2 = counter2 + 1;

      if(counter2 == 61)
      {
        counter2 = counter2 - 60;
      }

    }
  }
  previousState2 = currentState2;
  //  delay(50);
}

//==================================

void loopswitch3()
{
  pinMode(switchPin3, INPUT);
  val3= digitalRead(switchPin3); // read input value
  if (val3 == HIGH) 
  { // check if the input is HIGH (button released)
    currentState3 = 1;
  }
  else 
  {
    currentState3 = 0;
  }
  if(currentState3 != previousState3)
  {
    if(currentState3 == 1)
    {
      counter3 = counter3 + 1;

      if(counter3 == 4)
      {
        counter3 = counter3 - 60;

      }

    }
  }
  previousState3 = currentState3;
  //delay(50);
}

//=================================================
//Buzzer

void loopsound() 
{
  // iterate over the notes of the melody:
  analogWrite(speakerOut, 150);  
  for (int thisNote = 0; thisNote < 8; thisNote++) 
  {

    // to calculate the note duration, take one second 
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000/noteDurations[thisNote];
    tone(44, melody[thisNote],noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(44);
  }
  val3 = digitalRead(switchPin3);
  //delay(1000);
}

//===================================================

//Set time

void setTime()
{
  do
  {
    lcd.setCursor(0, 0); //top,left  
    lcd.setCursor(0, 0); 
    lcd.print("Set time for c1k");

    loopswitch1();
    loopswitch2();

    lcd.setCursor(0, 2); //bottom,left
    lcd.print("   ");     
    lcd.setCursor(0, 2); 
    lcd.print(counter1);

    lcd.setCursor(2, 2); // bottom,2 rows to the right
    lcd.print(":");

    lcd.setCursor(3, 2); // bottom,3 rows to the right
    lcd.print("   ");     
    lcd.setCursor(3, 2); 
    lcd.print(counter2);

    val3= digitalRead(switchPin3); // read input value
  }
  while(val3 != HIGH);    

  ch1 = counter1;
  cm1 = counter2;
}

//========================================
void timeup()
{
  do
  {
    lcd.clear();
    digitalWrite(led, HIGH);
    loopsound();
  }
  while(val3 != HIGH);

  do
  {
    loopswitch3();
    digitalWrite(led,LOW);
    noTone;
    val3= digitalRead(switchPin3);
  }
  while (val3 != HIGH);


}

//==================

The code that is not working.This program is not yet done.

#include <LiquidCrystal.h>
#include "pitches.h"
#include <Wire.h>
#include "DS1307.h"
#include <time.h>

void loopswitch1(void);
void loopswitch2(void);
void loopswitch3(void);
void loopsound(void);
void printTime(void);
void setupTime(void);
void setTime(void);
void timeup(void);
void blinklight(void);

LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );

int switchPin1 =48; // choose the input pin (for a pushbutton)
int val1 = 0; // variable for reading the pin status
int counter1 = 0;
int currentState1 = 0;
int previousState1 = 0;

int switchPin2 =49; // choose the input pin (for a pushbutton)
int val2 = 0; // variable for reading the pin status
int counter2 = 0;
int currentState2 = 0;
int previousState2 = 0;

int switchPin3 =50; // choose the input pin (for a pushbutton)
int val3 = 0; // variable for reading the pin status
int counter3 = 0;
int currentState3 = 0;
int previousState3 = 0;
int currenstate = 0;

int ch1 = 0;
int cm1 = 0;
int ch2 = 0;
int cm2 = 0;

int led1 = 28;
int led2 = 30;

int act1 = 24;
int act2 = 26;

int speakerOut = 44;  

int melody[] = {
  NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  4, 8, 8, 4,4,4,4,4 };

DS1307 clock;//define a object of DS1307 class

void setup() 
{
  Serial.begin(9600);
  lcd.begin(16, 2);  //no. of columns x rows
  pinMode(switchPin1, INPUT); // declare pushbutton as input
  setupTime();
  pinMode( led1, OUTPUT);
  pinMode( led2, OUTPUT);
  pinMode( act1, OUTPUT);
  pinMode( act2, OUTPUT);

}

void loop()
{
  setTime();

  if(val3 != HIGH) 
  {  
    ch1 = counter1;
    cm1 = counter2;
    setTime();
  }


  {
    ch2 = counter1;
    cm2 = counter2;
  } 

  do
  {
    lcd.clear();
    printTime();
  }
  while((clock.hour != ch1)||(clock.minute != cm1)); // Use OR logic because of the "!=" logic.

  do
  {
    timeup();
  }
  while(val3 != HIGH);

  do
  {
    loopswitch3();
    digitalWrite(led1,LOW);
    noTone;
    val2= digitalRead(switchPin2);
  }
  while (val2 != HIGH);

  do
  {
    lcd.clear();
    printTime();
  }
  while((clock.hour != ch2)||(clock.minute != cm2));

  do
  {
    timeup();
  }
  while(val3 != HIGH);

  loopswitch3();

  if(val3 >= 2)

  do
  {
    timeup();

  }
  while(val3 != HIGH);                  

}


//========================================

void setupTime()
{
  clock.begin();
  clock.fillByYMD(2013,7,24);//Jan 19,2013
  clock.fillByHMS(1,1,45);//15:28 30"
  clock.fillDayOfWeek(SUN);//Saturday
  clock.setTime();//write time to the RTC chip
}
void printTime()
{
  clock.getTime();
  lcd.setCursor(0, 0); //bottom,left
  lcd.print("  ");     
  lcd.setCursor(0, 0); 
  lcd.print(clock.hour, DEC);

  lcd.setCursor(2, 0); // bottom,2 rows to the right
  lcd.print(":");

  lcd.setCursor(3, 0); //bottom,left
  lcd.print("  ");     
  lcd.setCursor(3, 0); 
  lcd.print(clock.minute, DEC);

  lcd.setCursor(5, 0); // bottom,2 rows to the right
  lcd.print(":");

  lcd.setCursor(6, 0); //bottom,left
  lcd.print("  ");     
  lcd.setCursor(6, 0); 
  lcd.print(clock.second, DEC);

  lcd.setCursor(0, 2); //bottom,left
  lcd.print("  ");     
  lcd.setCursor(0, 2); 
  lcd.print(clock.month, DEC);

  lcd.setCursor(2, 2); // bottom,2 rows to the right
  lcd.print("/");

  lcd.setCursor(3, 2); //bottom,left
  lcd.print("  ");     
  lcd.setCursor(3, 2); 
  lcd.print(clock.dayOfMonth, DEC);

  lcd.setCursor(5, 2); // bottom,2 rows to the right
  lcd.print("/");

  lcd.setCursor(6, 2); //bottom,left
  lcd.print("  ");     
  lcd.setCursor(6, 2); 
  lcd.print(clock.year+2000, DEC);
  lcd.print("  ");

  switch (clock.dayOfWeek)
  {
  case MON:
    lcd.print("MON");
    break;
  case TUE:
    lcd.print("TUE");
    break;
  case WED:
    lcd.print("WED");
    break;
  case THU:
    lcd.print("THU");
    break;
  case FRI:
    lcd.print("FRI");
    break;
  case SAT:
    lcd.print("SAT");
    break;
  case SUN:
    lcd.print("SUN");
    break;
  }
  delay(1000);
}
//=========================================

void loopswitch1()
{
  val1 = digitalRead(switchPin1); // read input value

  if (val1 == HIGH) 
  { // check if the input is HIGH (button released)
    currentState1 = 1;
  }
  else 
  {
    currentState1 = 0;
  }

  if(currentState1 != previousState1)
  {
    if(currentState1 == 1)
    {
      counter1 = counter1 + 1;

      if(counter1 == 25)
      {
        counter1 = counter1 - 24;
      }

      //Serial.print("\b\b"); 
      //Serial.print(counter1);
    }
  }

  previousState1 = currentState1;

  //  delay(50);
}

//=====================================

void loopswitch2()
{
  pinMode(switchPin2, INPUT);
  val2 = digitalRead(switchPin2); // read input value
  if (val2 == HIGH) 
  { // check if the input is HIGH (button released)
    currentState2 = 1;
  }
  else 
  {
    currentState2 = 0;
  }
  if(currentState2 != previousState2)
  {
    if(currentState2 == 1)
    {
      counter2 = counter2 + 1;

      if(counter2 == 61)
      {
        counter2 = counter2 - 60;
      }

    }
  }
  previousState2 = currentState2;
  //  delay(50);
}

//==================================

void loopswitch3()
{
  pinMode(switchPin3, INPUT);
  val3= digitalRead(switchPin3); // read input value
  if (val3 == HIGH) 
  { // check if the input is HIGH (button released)
    currentState3 = 1;
  }
  else 
  {
    currentState3 = 0;
  }
  if(currentState3 != previousState3)
  {
    if(currentState3 == 1)
    {
      counter3 = counter3 + 1;

      if(counter3 == 4)
      {
        counter3 = counter3 - 60;

      }

    }
  }
  previousState3 = currentState3;
  //delay(50);
}

//=================================================
//Buzzer

void loopsound() 
{
  // iterate over the notes of the melody:
  analogWrite(speakerOut, 150);  
  for (int thisNote = 0; thisNote < 8; thisNote++) 
  {

    // to calculate the note duration, take one second 
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000/noteDurations[thisNote];
    tone(44, melody[thisNote],noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(44);
  }
  val3 = digitalRead(switchPin3);
  //delay(1000);
}

//===================================================

//Set time

void setTime()
{
  lcd.setCursor(0, 0); //top,left  
  lcd.setCursor(0, 0); 
  lcd.print("Set time for c1k");

  loopswitch1();
  loopswitch2();

  lcd.setCursor(0, 2); //bottom,left
  lcd.print("   ");     
  lcd.setCursor(0, 2); 
  lcd.print(counter1);

  lcd.setCursor(2, 2); // bottom,2 rows to the right
  lcd.print(":");

  lcd.setCursor(3, 2); // bottom,3 rows to the right
  lcd.print("   ");     
  lcd.setCursor(3, 2); 
  lcd.print(counter2);
  val3= digitalRead(switchPin3);
}

//========================================
void timeup()
{
  digitalWrite(led1, HIGH);
  loopsound();       
  val3= digitalRead(switchPin3);    
}
//==================
if(val3 != HIGH);

Nope.

Code that wanders across the page for no good reason is hard to read.

Try using the auto-format tool in the IDE before posting.

Fixed. Nope?

Fixed

All of them? And?

Sorry i meant, i formatted the code already but i have not fixed the problem yet.

But you haven't removed the semicolons from your "if"s..?

Ohh okay, i removed them already

i removed them already

Not in the code above (reply #5, last edit 11:36) you haven't.

I saw one and i removed it already, can i just ask how it affects my program without them? it compiles even with them so i don't really know how it affects the code.

I saw one and i removed it already

There's more than one (or at least that's the way it was when you posted originally.

it compiles even with them so i don't really know how it affects the code.

I can write all kinds of code that compiles but does nothing useful.

if (x == 3);
{  
  doSomething ();
}

You might imagine the "doSomething()" only gets called if "x" is 3. Wrong. It always gets called because the only "conditional" bit is the semicolon, which is this case is an empty expression.

So if it does not have a semicolon, it is not a conditional bit and will always get called?

if (x == 3)
{  
  doSomething ();
}

Note, now no semicolon, so "doSomething()" only gets called if x has the value 3.

Post your latest code. Don't just say "it doesn't work", tell us what it does do that it should not, and what it does not do that it should.

This is my latest code.What i want it do is to display the “Set time for clk” and run loopswitch 1 & 2 so that i can set the time and once i set the first timing, it will go to another set time when i press switch 3. The thing that is happening now is that it goes immediately to print time.

#include <LiquidCrystal.h>
#include "pitches.h"
#include <Wire.h>
#include "DS1307.h"
#include <time.h>

void loopswitch1(void);
void loopswitch2(void);
void loopswitch3(void);
void loopsound(void);
void printTime(void);
void setupTime(void);
void setTime(void);
void timeup(void);
void blinklight(void);

LiquidCrystal lcd( 8, 9, 4, 5, 6, 7 );

int switchPin1 =48; // choose the input pin (for a pushbutton)
int val1 = 0; // variable for reading the pin status
int counter1 = 0;
int currentState1 = 0;
int previousState1 = 0;

int switchPin2 =49; // choose the input pin (for a pushbutton)
int val2 = 0; // variable for reading the pin status
int counter2 = 0;
int currentState2 = 0;
int previousState2 = 0;

int switchPin3 =50; // choose the input pin (for a pushbutton)
int val3 = 0; // variable for reading the pin status
int counter3 = 0;
int currentState3 = 0;
int previousState3 = 0;
int currenstate = 0;

int ch1 = 0;
int cm1 = 0;
int ch2 = 0;
int cm2 = 0;

int led1 = 28;
int led2 = 30;

int act1 = 24;
int act2 = 26;

int speakerOut = 44;  

int melody[] = {
  NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  4, 8, 8, 4,4,4,4,4 };

DS1307 clock;//define a object of DS1307 class

void setup() 
{
  Serial.begin(9600);
  lcd.begin(16, 2);  //no. of columns x rows
  pinMode(switchPin1, INPUT); // declare pushbutton as input
  setupTime();
  pinMode( led1, OUTPUT);
  pinMode( led2, OUTPUT);
  pinMode( act1, OUTPUT);
  pinMode( act2, OUTPUT);

}

void loop()
{
  setTime();

  if(val3 != HIGH) 
  {  
    ch1 = counter1;
    cm1 = counter2;
    setTime();
  }

  if(val3 != HIGH) 
  {
    ch2 = counter1;
    cm2 = counter2;
  } 

  do
  {
    lcd.clear();
    printTime();
  }
  while((clock.hour != ch1)||(clock.minute != cm1)); // Use OR logic because of the "!=" logic.

  do
  {
    timeup();
  }
  while(val3 != HIGH);

  do
  {
    loopswitch3();
    digitalWrite(led1,LOW);
    noTone;
    val2= digitalRead(switchPin2);
  }
  while (val2 != HIGH);

  do
  {
    lcd.clear();
    printTime();
  }
  while((clock.hour != ch2)||(clock.minute != cm2));

  do
  {
    timeup();
  }
  while(val3 != HIGH);

  loopswitch3();

  if(val3 >= 2)

  do
  {
    timeup();

  }
  while(val3 != HIGH);                  

}


//========================================

void setupTime()
{
  clock.begin();
  clock.fillByYMD(2013,7,24);//Jan 19,2013
  clock.fillByHMS(1,1,45);//15:28 30"
  clock.fillDayOfWeek(SUN);//Saturday
  clock.setTime();//write time to the RTC chip
}
void printTime()
{
  clock.getTime();
  lcd.setCursor(0, 0); //bottom,left
  lcd.print("  ");     
  lcd.setCursor(0, 0); 
  lcd.print(clock.hour, DEC);

  lcd.setCursor(2, 0); // bottom,2 rows to the right
  lcd.print(":");

  lcd.setCursor(3, 0); //bottom,left
  lcd.print("  ");     
  lcd.setCursor(3, 0); 
  lcd.print(clock.minute, DEC);

  lcd.setCursor(5, 0); // bottom,2 rows to the right
  lcd.print(":");

  lcd.setCursor(6, 0); //bottom,left
  lcd.print("  ");     
  lcd.setCursor(6, 0); 
  lcd.print(clock.second, DEC);

  lcd.setCursor(0, 2); //bottom,left
  lcd.print("  ");     
  lcd.setCursor(0, 2); 
  lcd.print(clock.month, DEC);

  lcd.setCursor(2, 2); // bottom,2 rows to the right
  lcd.print("/");

  lcd.setCursor(3, 2); //bottom,left
  lcd.print("  ");     
  lcd.setCursor(3, 2); 
  lcd.print(clock.dayOfMonth, DEC);

  lcd.setCursor(5, 2); // bottom,2 rows to the right
  lcd.print("/");

  lcd.setCursor(6, 2); //bottom,left
  lcd.print("  ");     
  lcd.setCursor(6, 2); 
  lcd.print(clock.year+2000, DEC);
  lcd.print("  ");

  switch (clock.dayOfWeek)
  {
  case MON:
    lcd.print("MON");
    break;
  case TUE:
    lcd.print("TUE");
    break;
  case WED:
    lcd.print("WED");
    break;
  case THU:
    lcd.print("THU");
    break;
  case FRI:
    lcd.print("FRI");
    break;
  case SAT:
    lcd.print("SAT");
    break;
  case SUN:
    lcd.print("SUN");
    break;
  }
  delay(1000);
}
//=========================================

void loopswitch1()
{
  val1 = digitalRead(switchPin1); // read input value

  if (val1 == HIGH) 
  { // check if the input is HIGH (button released)
    currentState1 = 1;
  }
  else 
  {
    currentState1 = 0;
  }

  if(currentState1 != previousState1)
  {
    if(currentState1 == 1)
    {
      counter1 = counter1 + 1;

      if(counter1 == 25)
      {
        counter1 = counter1 - 24;
      }

      //Serial.print("\b\b"); 
      //Serial.print(counter1);
    }
  }

  previousState1 = currentState1;

  //  delay(50);
}

//=====================================

void loopswitch2()
{
  pinMode(switchPin2, INPUT);
  val2 = digitalRead(switchPin2); // read input value
  if (val2 == HIGH) 
  { // check if the input is HIGH (button released)
    currentState2 = 1;
  }
  else 
  {
    currentState2 = 0;
  }
  if(currentState2 != previousState2)
  {
    if(currentState2 == 1)
    {
      counter2 = counter2 + 1;

      if(counter2 == 61)
      {
        counter2 = counter2 - 60;
      }

    }
  }
  previousState2 = currentState2;
  //  delay(50);
}

//==================================

void loopswitch3()
{
  pinMode(switchPin3, INPUT);
  val3= digitalRead(switchPin3); // read input value
  if (val3 == HIGH) 
  { // check if the input is HIGH (button released)
    currentState3 = 1;
  }
  else 
  {
    currentState3 = 0;
  }
  if(currentState3 != previousState3)
  {
    if(currentState3 == 1)
    {
      counter3 = counter3 + 1;

      if(counter3 == 4)
      {
        counter3 = counter3 - 60;

      }

    }
  }
  previousState3 = currentState3;
  //delay(50);
}

//=================================================
//Buzzer

void loopsound() 
{
  // iterate over the notes of the melody:
  analogWrite(speakerOut, 150);  
  for (int thisNote = 0; thisNote < 8; thisNote++) 
  {

    // to calculate the note duration, take one second 
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000/noteDurations[thisNote];
    tone(44, melody[thisNote],noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(44);
  }
  val3 = digitalRead(switchPin3);
  //delay(1000);
}

//===================================================

//Set time

void setTime()
{
  lcd.setCursor(0, 0); //top,left  
  lcd.setCursor(0, 0); 
  lcd.print("Set time for c1k");

  loopswitch1();
  loopswitch2();

  lcd.setCursor(0, 2); //bottom,left
  lcd.print("   ");     
  lcd.setCursor(0, 2); 
  lcd.print(counter1);

  lcd.setCursor(2, 2); // bottom,2 rows to the right
  lcd.print(":");

  lcd.setCursor(3, 2); // bottom,3 rows to the right
  lcd.print("   ");     
  lcd.setCursor(3, 2); 
  lcd.print(counter2);
  val3= digitalRead(switchPin3);
}

//========================================
void timeup()
{
  digitalWrite(led1, HIGH);
  loopsound();       
  val3= digitalRead(switchPin3);    
}
//==================
 if(val3 >= 2);

How much longer are you going to keep this up?

Okay i didn't see that, removed.