When i press the push button it goes so fast

Hello everybody. This is my first post here. I have a problem with button. I want to do alarm clock and i want to set the alarm by buttons. I have 2 buttons, one for counter and one for saving the time. Counter button works good but when press enter button it goes so fast.

#include <LiquidCrystal.h>
#include <Stepper.h>
#include <DS3231.h>
DS3231  rtc(SDA, SCL);
LiquidCrystal lcd(12, 11, 6, 5, 4, 3);

const int butonSayac = 2;
const int butonEnter = 7;
int saat = 0;
int dakika = 0;
int butonDurumuSayac = LOW;
int butonDurumuSayacDakika = LOW;
int butonDurumuSayacIlac = LOW;
int butonDurumuSayacGunde = LOW;
int butonEnterDurum = LOW;
int butonEnterDurumDakika = LOW;
int butonEnterDurumIlac = LOW;
int butonEnterDurumGunde = LOW;
int saatTemp;
int dakikaTemp;
int ilacNoTemp;
int ilacTemp;
int ilacGunde = 0;
int ilacNumber = 1;
int kutuBaslangic;
int kutuSecilen;
int kutuAnlik;
int i;

void setup(){
  pinMode(butonSayac, INPUT);
  pinMode(butonEnter, INPUT);
  Serial.begin(9600);
  rtc.begin();
  lcd.begin(16,2);
  for(i=0;i<7;i++){
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(i+1);
  lcd.print(".kutu: ");
  lcd.setCursor(0,1);
  lcd.print("Saat: ");
  lcd.print(saat);
  
  while(butonEnterDurum == LOW){
    butonDurumuSayac = digitalRead(butonSayac);
    
    if(butonDurumuSayac == HIGH){
      delay(10);
      saat++;
      if(saat > 23){
        saat = 0;
      }
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print(i+1);
      lcd.print(".kutu: ");
      lcd.setCursor(0,1);
      lcd.print("Saat: ");
      lcd.print(saat);
      
      while(butonDurumuSayac == HIGH){
        butonDurumuSayac = digitalRead(butonSayac);          
      }
      delay(10);
    }

    butonEnterDurum = digitalRead(butonEnter);
    delay(10);  
  }
  
  while(butonEnterDurum == HIGH){
    saatTemp = saat;
    butonEnterDurum = LOW;
    butonDurumuSayac = LOW;
  }

  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Dakika: ");
  lcd.print(dakika);

  while(butonEnterDurumDakika == LOW){
    butonDurumuSayacDakika = digitalRead(butonSayac);
    
    if(butonDurumuSayacDakika == HIGH){
      delay(10);
      dakika++;
      
      if(dakika>59){
        dakika = 0;
      }
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Dakika: ");
      lcd.print(dakika);

      while(butonDurumuSayacDakika == HIGH){
        butonDurumuSayacDakika = digitalRead(butonSayac);          
      }
      delay(10);
    }
    butonEnterDurumDakika = digitalRead(butonEnter);
    delay(10);  
  } 
  
  while(butonEnterDurumDakika == HIGH){
    dakikaTemp = dakika;
    butonEnterDurumDakika = LOW;
    butonDurumuSayacDakika = LOW;
    ////break;
  }

  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Gunde kac adet:");
  lcd.print(ilacGunde);
  
  while(butonEnterDurumGunde == LOW){
    butonDurumuSayacGunde = digitalRead(butonSayac);
  
    if(butonDurumuSayacGunde == HIGH){
      delay(10);
      ilacGunde++;
    
      if( ilacGunde > 8 ){
        ilacGunde = 0;
      }
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Gunde kac adet:");
      lcd.print(ilacGunde);

      while(butonDurumuSayacGunde == HIGH){
        butonDurumuSayacGunde = digitalRead(butonSayac);          
      }
      delay(10);
    }
    butonEnterDurumGunde = digitalRead(butonEnter);
    delay(10);  
  } 
  
  while(butonEnterDurumGunde == HIGH){
    ilacTemp = ilacGunde;
    butonEnterDurumGunde = LOW;
    butonDurumuSayacGunde = LOW;
    break;
    }  
  }
}
void loop(){
}

duzenleme.ino (3.57 KB)

Welcome to the fourm! Please read the sticky posts at the top of the forum about how to post code using code tags. It will help people help you.

The problem seems to be this block

    while (butonEnterDurum == HIGH) {
      saatTemp = saat;
      butonEnterDurum = LOW;
      butonDurumuSayac = LOW;
    }

After someone presses enter, butonEnterDurum is HIGH and you immediately set it LOW so this while loop only executes 1 time. You need to continue looping until the person releases the enter button

    while (butonEnterDurum == HIGH) {
      butonEnterDurum = digitalRead(butonEnter);
    }
    saatTemp = saat;
    butonDurumuSayac = LOW;

blh64:
Welcome to the fourm! Please read the sticky posts at the top of the forum about how to post code using code tags. It will help people help you.

The problem seems to be this block

    while (butonEnterDurum == HIGH) {

saatTemp = saat;
      butonEnterDurum = LOW;
      butonDurumuSayac = LOW;
    }




After someone presses enter, butonEnterDurum is HIGH and you immediately set it LOW so this while loop only executes 1 time. You need to continue looping until the person releases the enter button


while (butonEnterDurum == HIGH) {
      butonEnterDurum = digitalRead(butonEnter);
    }
    saatTemp = saat;
    butonDurumuSayac = LOW;

I will read the posting rules and thank you so much :slight_smile: It works perfect.