Hilfe beim ersten Projekt gesucht

Hallo zusammen.
Ich habe nachdem ich mir so einige Videos, Hilfeseiten und Foreneinträge angesehe habe, zum ersten Mal mit Arduino beschäftigt.
Programmiersprache ist eigentlich also eine Fremdsprache für mich.
Mein ersten Projekt "Krokodil" habe ich soweit fertig... Nur komme ich am Schluss nicht weiter.
Das Programm läuft ein "Schluss"-Void (void verloren) durch und sollte dann wieder auf Anfang (zustand1) springen.
Leider habe ich aber das Problem, dass die Tasten aus dem Loop nicht erkannt werden.
Vielleicht könnte mir hier jemand helfen...

(Ich weiß, dass ich mit vielen Variablen und If-Befehlen arbeite, aber wie gesagt = Anfänger)

Hier der komplette Code:

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,4);  // set the LCD address to 0x3F for a 16 chars and 2 line display

int tasterSelect=4;
int tasterHoch=7;
int tasterRunter=8;
int relais=9;
int reed=10; 

int red = 3;
int green = 6;
int blue = 5;

int HochGedrueckt = 0 ;
int RunterGedrueckt = 0;
int SelectGedrueckt = 0;


int tasterStatusHoch = LOW;           // aktuelles Signal vom Eingangspin
int tasterGedruecktHoch = 0;          // abfragen ob Taster gedrückt war
int tasterStatusRunter = LOW;           // aktuelles Signal vom Eingangspin
int tasterGedruecktRunter = 0;          // abfragen ob Taster gedrückt war
int tasterStatusSelect = LOW;           // aktuelles Signal vom Eingangspin
int tasterGedruecktSelect = 0;          // abfragen ob Taster gedrückt war

int entprellZeit = 200;           // Zeit für Entprellung, anpassen!

unsigned long tasterZeitHoch = 0;     // Zeit beim drücken des Tasters
unsigned long tasterZeitSelect = 0;     // Zeit beim drücken des Tasters
unsigned long tasterZeitRunter = 0;     // Zeit beim drücken des Tasters

int ledred;
int ledgreen;
int ledblue;

int counter = 0;
int vorgabe = 1;
int fuellangabe = 0;
int fuellung = 0;
int zufallszahl = 0;

int menu1 = 0;
int menu2 = 0;
int menu6 = 0;
int menuplay = 0;
int zustand = 0;
int play;
int stop;
int zustandplay;

int reedState = 0;
boolean reedzustand = true;

int checkauf;
int checkzu;



void setup() {
  Serial.begin(9600);

  lcd.init();
  lcd.clear();    
  lcd.backlight();    

  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(tasterRunter, INPUT);
  pinMode(tasterSelect, INPUT);
  pinMode(tasterHoch, INPUT);
  pinMode(reed, INPUT);
  pinMode(relais, OUTPUT);

analogWrite(blue, 0);
analogWrite(red, 0);
 analogWrite(green, 255);

  lcd.print("Schnapsi");
  lcd.setCursor(0,1);
  lcd.print("Das kleine Krokodil");
  lcd.setCursor(0,2);
  lcd.print("Viel Spass!");
  delay(300);
  menu1 = 1;
  zustand = 1;
  fuellung = 1;
  zustand1();


}

void loop() 
{



/////////////////////taster /////////

///////////////hoch///////////

tasterStatusHoch = digitalRead(tasterHoch); 
  Serial.println(tasterStatusHoch);
        if (tasterStatusHoch == HIGH) 
          { 
          tasterZeitHoch = millis();     
          tasterGedruecktHoch = 1;   
          }
        if ((millis() - tasterZeitHoch > entprellZeit) && tasterGedruecktHoch == 1)
          {
            HochGedrueckt = 1;   
            tasterGedruecktHoch = 0;
          }
  ///////////runter /////////////
        tasterStatusRunter = digitalRead(tasterRunter); 
        if (tasterStatusRunter == HIGH) 
          { 
            tasterZeitRunter = millis();     
            tasterGedruecktRunter = 1;      
          }
        if ((millis() - tasterZeitRunter > entprellZeit) && tasterGedruecktRunter == 1)
          {
            RunterGedrueckt = 1;
            tasterGedruecktRunter = 0; 
          }

  ///////////select /////////////
          tasterStatusSelect = digitalRead(tasterSelect); 
        if (tasterStatusSelect == HIGH) 
          { 
            tasterZeitSelect = millis();     
            tasterGedruecktSelect = 1;      
          }
        if ((millis() - tasterZeitSelect > entprellZeit) && tasterGedruecktSelect == 1)
          {
            SelectGedrueckt = 1;
            tasterGedruecktSelect = 0; 
          }

///////////////////////////


 ////taster zustand 1 /////


    if (HochGedrueckt == 1 && zustand == 1)
          {
            HochGedrueckt = 0;
            menu1--;
            zustand1();
            delay (200);
          }

    if (RunterGedrueckt == 1 && zustand == 1)
          {
            RunterGedrueckt = 0;
            menu1++;
            zustand1();
            delay (200);
          }

    if (SelectGedrueckt == 1 && zustand == 1 && menu1 == 1)
          {
            SelectGedrueckt = 0;
            menu1 = 0;
            menu2 = 1;
            zustand = 2;
            zustand2();
          }
        if (SelectGedrueckt == 1 && zustand == 1 && menu1 == 2)
          {
            SelectGedrueckt = 0;
            menu1 = 0;
            zustand = 5;
            zustand5(); 
            delay (200);
          }
        if (SelectGedrueckt == 1 && zustand == 1 && menu1 == 3)
          {
            SelectGedrueckt = 0;
            menu1 = 0;
            menu6 = 1;
            zustand = 6;
            zustand6();
            delay (200);
          }

 ////taster zustand 2 /////

        if (HochGedrueckt == 1 && zustand == 2)
          {
            HochGedrueckt = 0;
            menu2 = 1;
            delay (200);
            zustand2();
          }

        if (RunterGedrueckt == 1 && zustand == 2)
          {
            RunterGedrueckt = 0;
            menu2 = 2;
            delay (200);
            zustand2();
          }

        if (SelectGedrueckt == 1 && zustand == 2 && menu2 == 1)
          {
            SelectGedrueckt = 0;
            menu1 = 1;
            zustand = 3;
            zustand3();
            delay (200);
          }
        if (SelectGedrueckt == 1 && zustand == 2 && menu2 == 2)
          {
            SelectGedrueckt = 0;
            menu1 = 1;
            zustand = 4; 
            zustand4();
            delay (200);
          }
        if (SelectGedrueckt == 1 && zustand == 2 && menu2 == 3)
          {
            SelectGedrueckt = 0;
            menu1 = 1;
            zustand = 6;
            zustand6();
            delay (200);
          }


  ///////// taster zustand 4 /////

        if (HochGedrueckt == 1 && zustand == 4)
          {
            vorgabe--;
            HochGedrueckt = 0;
            zustand4();
            delay (200);
          }
        if (RunterGedrueckt == 1 && zustand == 4)
          {
            vorgabe++;
            RunterGedrueckt = 0;
            zustand4();
            delay (200);  
          }

        if (SelectGedrueckt == 1 && zustand == 4)
          {
            SelectGedrueckt = 0;
            zustand = 1;
            lcd.clear();
            lcd.print("Fester Wert");
            lcd.setCursor(0,1);
            lcd.print("eingestellt");
            delay (2000);
            play = 1;
            playtime();
            delay (200);
          }
          

            ///////// taster zustand 5 /////

        if (SelectGedrueckt == 1 && zustand == 5)
          {
            analogWrite(green, 0);
            analogWrite(red, 0);
            analogWrite(blue, 255);
            digitalWrite(relais, LOW);
            delay (500);
            lcd.clear();
            lcd.print("Spuelen Stop");
            delay (1000);
            lcd.clear();
            lcd.print("Spuelen Beendet");
            delay (3000);
            zustand = 1;
            analogWrite(blue, 0);
            zustand1();

          }
        if (RunterGedrueckt == 1 && zustand == 5)
          {
            digitalWrite(relais, LOW);
            delay (500);
            lcd.clear();
            lcd.print("Spuelen Stop");
            delay (1000);
            lcd.clear();
            lcd.print("Spuelen Beendet");
            delay (3000);
            zustand = 1;
            zustand1();

          }
          if (HochGedrueckt == 1 && zustand == 5)
          {
            digitalWrite(relais, LOW);
            delay (500);
            lcd.clear();
            lcd.print("Spuelen Stop");
            delay (3000);
            lcd.clear();
            lcd.print("Spuelen Beendet");
            delay (2000);
            zustand = 1;
            zustand1();

          }
   //////////////// taster zustand 6 //////////

        if (HochGedrueckt == 1 && zustand == 6)
          {
            menu6--;
            zustand6();
            delay (200);
          }

        if (RunterGedrueckt == 1 && zustand == 6)
          {
            menu6++;  
            zustand6();
            delay (200);
          }

        if (SelectGedrueckt == 1 && zustand == 6)
          {
            fuellangabe = fuellung;
            zustand = 1;
            play = 1;
            playtime();
          }
}


void zustand1(){

      /////////////////// zustand 1 /////////////
  switch (menu1)
    {
      case 0:
          menu1 = 1;
          break;
      case 1:
          lcd.clear();
          lcd.print("MENUE");
          lcd.setCursor(0,1);
          lcd.print(">Spielmodus");
          lcd.setCursor(0,2);
          lcd.print(" Spuelen");
          lcd.setCursor(0,3);
          lcd.print(" Fuellangabe");
          break;
      case 2:
          lcd.clear();
          lcd.print("MENUE");
          lcd.setCursor(0,1);
          lcd.print(" Spielmodus");
          lcd.setCursor(0,2);
          lcd.print(">Spuelen");
          lcd.setCursor(0,3);
          lcd.print(" Fuellangabe");
          break;
      case 3:
          lcd.clear();
          lcd.print("MENUE");
          lcd.setCursor(0,1);
          lcd.print(" Spielmodus");
          lcd.setCursor(0,2);
          lcd.print(" Spuelen");
          lcd.setCursor(0,3);
          lcd.print(">Fuellangabe");
          break;
      case 4:
          menu1 = 3;
          break;
      }
}

void zustand2() 
/// auswahl zufall / fester wert //// zustand 2 /////////
{
  switch (menu2)
    {
      case 0:
          menu2 = 1;
          break;
      case 1:
          lcd.clear();
          lcd.print("MENUE");
          lcd.setCursor(0,1);
          lcd.print(">Zufall");
          lcd.setCursor(0,2);
          lcd.print(" Fester Wert");
          break;
      case 2:
          lcd.clear();
          lcd.print("MENUE");
          lcd.setCursor(0,1);
          lcd.print(" Zufall");
          lcd.setCursor(0,2);
          lcd.print(">Fester Wert");
          break;
      case 3:
          menu2 = 1;
          break;
      }
 }

void zustand3() 
{
    /// zufall genieren ///

         zufallszahl = random(1,5);
         zufallszahl = random(1,8);
         zufallszahl = random(1,10);
        lcd.clear();
        lcd.print("Zufallszahl erstellt");
        vorgabe = zufallszahl;
        delay (1000);
        play = 1;
        playtime();
}


void zustand4() 
{
  /// fester wert //
        lcd.clear();
        lcd.print("Fester Wert einstellen");
        lcd.setCursor(0,1);
        lcd.print("+ / - druecken");
        lcd.setCursor(0,2);
        lcd.print(vorgabe);
        lcd.print("  ausgewaehlt");
}

void zustand5() 
    {
  /// spuelen //
    lcd.clear();
    lcd.print("Spuelen startet");
    delay (1000);
    digitalWrite(relais, HIGH);
    } 

void zustand6() 
    {
  switch (menu6)
    {
      case 0:
          menu6 = 1;
          break;
      case 1:
          lcd.clear();
          lcd.print("FUELLANGABE");
          lcd.setCursor(0,1);
          lcd.print(">2 CL");
          lcd.setCursor(0,2);
          lcd.print(" 1 CL");
          fuellangabe = 2;
          break;
      case 2:
          lcd.clear();
          lcd.print("FUELLANGABE");
          lcd.setCursor(0,1);
          lcd.print(" 2 CL");
          lcd.setCursor(0,2);
          lcd.print(">1 CL");
          fuellangabe = 1;
          break;
      case 3:
          menu6 = 2;
          break;
      }
 }

void playtime()

{
stop = 0;
 reedzustand = true;
reedState =digitalRead(reed);
 if (reedState == HIGH && play == 1 && stop == 0)
  {
    if (reedzustand == true)
    {
    stop = 1;
     analogWrite(green, 0);
      analogWrite(red, 255);
    lcd.clear();
    lcd.print("Bitte oeffnen");
    analogWrite(red, 0);
    analogWrite(red, 255);
    delay (100);
    analogWrite(red, 0);
    delay (100);
    analogWrite(green, 255);
    delay (1000);
    reedzustand = false;
    playtime();
    }
  }
  if (reedState == LOW && play == 1 && stop == 0)
  {
    if (reedzustand == true)
    {
       analogWrite(red, 0);
       analogWrite(green, 255);
      lcd.clear();
      delay (2000);
      play = 2;
      reedzustand = false;
      playtime();
    }
  }
reedState =digitalRead(reed);
  if (reedState == HIGH && play == 2 && stop == 0)
   { 
     if (reedzustand == true)
      {
      stop = 1;
      play = 0;
      schnapp();
      reedzustand = false;
      }
   }
  else {playtime();}
}

void schnapp()
{
          counter++;
          lcd.clear(); 
          analogWrite(green, 0);
          analogWrite(red, 255);
          delay (100);
          analogWrite(red, 0);
          delay (100);
          analogWrite(red, 255); 
          lcd.print("SCHNAPP!!!");
          lcd.setCursor(0,1);
          lcd.clear(); 
          lcd.print("ANZAHL:");
          lcd.setCursor(0,2);
          lcd.print(counter); 
          if (counter == vorgabe)
          {
           analogWrite(blue, 255);
           delay (100);
           analogWrite(blue, 0);
           analogWrite(red, 255);
           delay (100);
           analogWrite(red, 0);
           analogWrite(blue, 255);
           delay (100);
          lcd.clear();
          lcd.print("VERLOREN");
          analogWrite(blue, 0);
          analogWrite(red, 255);
          delay (100);
          analogWrite(red, 0);
          analogWrite(blue, 255);
          delay (100);
          analogWrite(red, 255);
          analogWrite(blue, 0);
          delay (100);
          analogWrite(red, 0);
          analogWrite(blue, 255);
          delay (100);
          analogWrite(blue, 0);
          analogWrite(red, 255);
          delay (100);
          analogWrite(red, 0);
          analogWrite(blue, 255);
          delay (100);
          analogWrite(red, 255);
          analogWrite(blue, 0);
          delay (100);
          analogWrite(red, 0);
          analogWrite(blue, 0);
          delay (3000);
          lcd.clear();
          verloren();
          }
          if (counter != vorgabe)
          {
          delay (3000);
          play = 1;
          playtime();
          }

      }

void verloren()
 {
     lcd.clear(); 
     lcd.print("Verloren!");
     analogWrite(green, 0);
     analogWrite(blue, 255);
     analogWrite(red, 0);
     if (fuellung == 1) 
      {
      digitalWrite(relais, HIGH);
      delay (3000);
      digitalWrite(relais, LOW);
      }
    if (fuellung == 2)
      {
      digitalWrite(relais, HIGH);
      delay (3000);
       digitalWrite(relais, LOW);
      }
    lcd.clear();
    lcd.print("PROST");
    vorgabe = 0;
    fuellung = 1;
    counter = 0;
    stop = 0;
    zufallszahl = 0;
menu1 = 1; (NACHTRAG)
    analogWrite(blue, 0);
    lcd.clear();
    zustand1();
  }
  

[EDIT] Bildlink aus den Sketch genommen. Uwe [/EDIT]

Diese Aufrufe der delay() Funktion blockieren das erwartete Echzeitverhalten.

Line  88:   delay(300);
	Line 155:             delay (200);
	Line 163:             delay (200);
	Line 180:             delay (200);
	Line 189:             delay (200);
	Line 198:             delay (200);
	Line 206:             delay (200);
	Line 216:             delay (200);
	Line 224:             delay (200);
	Line 232:             delay (200);
	Line 243:             delay (200);
	Line 250:             delay (200);  
	Line 261:             delay (2000);
	Line 264:             delay (200);
	Line 276:             delay (500);
	Line 279:             delay (1000);
	Line 282:             delay (3000);
	Line 291:             delay (500);
	Line 294:             delay (1000);
	Line 297:             delay (3000);
	Line 305:             delay (500);
	Line 308:             delay (3000);
	Line 311:             delay (2000);
	Line 322:             delay (200);
	Line 329:             delay (200);
	Line 426:         delay (1000);
	Line 449:     delay (1000);
	Line 501:     delay (100);
	Line 503:     delay (100);
	Line 505:     delay (1000);
	Line 517:       delay (2000);
	Line 543:           delay (100);
	Line 545:           delay (100);
	Line 556:            delay (100);
	Line 559:            delay (100);
	Line 562:            delay (100);
	Line 567:           delay (100);
	Line 570:           delay (100);
	Line 573:           delay (100);
	Line 576:           delay (100);
	Line 579:           delay (100);
	Line 582:           delay (100);
	Line 585:           delay (100);
	Line 588:           delay (3000);
	Line 594:           delay (3000);
	Line 611:       delay (3000);
	Line 617:       delay (3000);

Was muss jetzt gemacht werden?
Redesign des Sketches unter der Verwendung von Timern auf der Basis der millis() Funktion.
Beim Redesign ist das Studium des IPO Modells hilfreich. Alle Funktionen einzeln testen und danach zum Gesamtprojekt zusammenlöten.

Nutze doch Serial Print Ausgaben um zu verfolgen wo dein Programm aktuell ist. Jede Funktion erhält am Anfang ein "funktionsname start" und am ende ein "funktionsname ende". Dann siehst du vermutlich wo du stecken bleibst.

Er ist ganz am ganz am Ende und Geht dann auch in Zustand1(). Nur werden die Taster welche im Loop darüber sind nicht erkannt...

das mit dem millis probiere ich mal...
ipo sieht sehr umständlich aus, aber auch das schaue ich mal an

du änderst mit dem Aufruf zustand1() nur die Anzeige.
Vermutlich musst du auch deine Variable zustand ändern.

Ein Programmablaufplan oder ein State Diagramm würde helfen Überblick zu bekommen.

ich seh es so:
nach verloren() wird einmal zustand1() aufgerufen aber er geht dann wieder in playtime

Eigentlich nicht.

INPUT: Sensoren, was auch immer das sind, einlesen
PROCESSING: mach was mit den Sensordaten
OUTPUT: die Ergebnisse von "mach was" ausgeben

so beginnt er wieder am Anfang:

#include <LiquidCrystal_I2C.h>

#define MARCEL 1

#if MARCEL
int tasterSelect = 4;
int tasterHoch = 7;
int tasterRunter = 8;
int relais = 9;
int reed = 10;
int red = 3;
int green = 6;
int blue = 5;
const uint8_t addr = 0x27;
#else
const uint8_t tasterSelect = A2;
const uint8_t tasterHoch = A1;
const uint8_t tasterRunter = A0;
const uint8_t relais = 9;
const uint8_t reed = A3;
const uint8_t red = 13;
const uint8_t green = 5;
const uint8_t blue = 6;
const uint8_t addr = 0x3F;
#endif
LiquidCrystal_I2C lcd(addr, 16, 4); // set the LCD address to 0x3F for a 16 chars and 2 line display

int HochGedrueckt = 0 ;
int RunterGedrueckt = 0;
int SelectGedrueckt = 0;

int tasterStatusHoch = LOW;           // aktuelles Signal vom Eingangspin
int tasterGedruecktHoch = 0;          // abfragen ob Taster gedrückt war
int tasterStatusRunter = LOW;           // aktuelles Signal vom Eingangspin
int tasterGedruecktRunter = 0;          // abfragen ob Taster gedrückt war
int tasterStatusSelect = LOW;           // aktuelles Signal vom Eingangspin
int tasterGedruecktSelect = 0;          // abfragen ob Taster gedrückt war

uint16_t entprellZeit = 200;           // Zeit für Entprellung, anpassen!   --> ansonsten warning

unsigned long tasterZeitHoch = 0;     // Zeit beim drücken des Tasters
unsigned long tasterZeitSelect = 0;     // Zeit beim drücken des Tasters
unsigned long tasterZeitRunter = 0;     // Zeit beim drücken des Tasters

int ledred;
int ledgreen;
int ledblue;

int counter = 0;
int vorgabe = 1;
int fuellangabe = 0;
int fuellung = 0;
int zufallszahl = 0;

int menu1 = 0;
int menu2 = 0;
int menu6 = 0;
int menuplay = 0;
int zustand = 0;
int play;
int stop;
int zustandplay;

int reedState = 0;
boolean reedzustand = true;

int checkauf;
int checkzu;

void setup() {
  Serial.begin(9600);

  lcd.init();
  lcd.clear();
  lcd.backlight();

  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(tasterRunter, INPUT);
  pinMode(tasterSelect, INPUT);
  pinMode(tasterHoch, INPUT);
  pinMode(reed, INPUT);
  pinMode(relais, OUTPUT);

  analogWrite(blue, 0);
  analogWrite(red, 0);
  analogWrite(green, 255);

  lcd.print("Schnapsi");
  lcd.setCursor(0, 1);
  lcd.print("Das kleine Krokodil");
  lcd.setCursor(0, 2);
  lcd.print("Viel Spass!");
  delay(300);
  menu1 = 1;
  zustand = 1;
  fuellung = 1;
  zustand1();
}

void loop()
{
  /////////////////////taster /////////

  ///////////////hoch///////////

  tasterStatusHoch = digitalRead(tasterHoch);
  //Serial.println(tasterStatusHoch);
  if (tasterStatusHoch == HIGH)
  {
    tasterZeitHoch = millis();
    tasterGedruecktHoch = 1;
  }
  if ((millis() - tasterZeitHoch > entprellZeit) && tasterGedruecktHoch == 1)
  {
    HochGedrueckt = 1;
    tasterGedruecktHoch = 0;
  }
  ///////////runter /////////////
  tasterStatusRunter = digitalRead(tasterRunter);
  if (tasterStatusRunter == HIGH)
  {
    tasterZeitRunter = millis();
    tasterGedruecktRunter = 1;
  }
  if ((millis() - tasterZeitRunter > entprellZeit) && tasterGedruecktRunter == 1)
  {
    RunterGedrueckt = 1;
    tasterGedruecktRunter = 0;
  }

  ///////////select /////////////
  tasterStatusSelect = digitalRead(tasterSelect);
  if (tasterStatusSelect == HIGH)
  {
    tasterZeitSelect = millis();
    tasterGedruecktSelect = 1;
  }
  if ((millis() - tasterZeitSelect > entprellZeit) && tasterGedruecktSelect == 1)
  {
    SelectGedrueckt = 1;
    tasterGedruecktSelect = 0;
  }

  ///////////////////////////


  ////taster zustand 1 /////


  if (HochGedrueckt == 1 && zustand == 1)
  {
    HochGedrueckt = 0;
    menu1--;
    zustand1();
    delay (200);
  }

  if (RunterGedrueckt == 1 && zustand == 1)
  {
    RunterGedrueckt = 0;
    menu1++;
    zustand1();
    delay (200);
  }

  if (SelectGedrueckt == 1 && zustand == 1 && menu1 == 1)
  {
    SelectGedrueckt = 0;
    menu1 = 0;
    menu2 = 1;
    zustand = 2;
    zustand2();
  }
  if (SelectGedrueckt == 1 && zustand == 1 && menu1 == 2)
  {
    SelectGedrueckt = 0;
    menu1 = 0;
    zustand = 5;
    zustand5();
    delay (200);
  }
  if (SelectGedrueckt == 1 && zustand == 1 && menu1 == 3)
  {
    SelectGedrueckt = 0;
    menu1 = 0;
    menu6 = 1;
    zustand = 6;
    zustand6();
    delay (200);
  }

  ////taster zustand 2 /////

  if (HochGedrueckt == 1 && zustand == 2)
  {
    HochGedrueckt = 0;
    menu2 = 1;
    delay (200);
    zustand2();
  }

  if (RunterGedrueckt == 1 && zustand == 2)
  {
    RunterGedrueckt = 0;
    menu2 = 2;
    delay (200);
    zustand2();
  }

  if (SelectGedrueckt == 1 && zustand == 2 && menu2 == 1)
  {
    SelectGedrueckt = 0;
    menu1 = 1;
    zustand = 3;
    zustand3();
    delay (200);
  }
  if (SelectGedrueckt == 1 && zustand == 2 && menu2 == 2)
  {
    SelectGedrueckt = 0;
    menu1 = 1;
    zustand = 4;
    zustand4();
    delay (200);
  }
  if (SelectGedrueckt == 1 && zustand == 2 && menu2 == 3)
  {
    SelectGedrueckt = 0;
    menu1 = 1;
    zustand = 6;
    zustand6();
    delay (200);
  }


  ///////// taster zustand 4 /////

  if (HochGedrueckt == 1 && zustand == 4)
  {
    vorgabe--;
    HochGedrueckt = 0;
    zustand4();
    delay (200);
  }
  if (RunterGedrueckt == 1 && zustand == 4)
  {
    vorgabe++;
    RunterGedrueckt = 0;
    zustand4();
    delay (200);
  }

  if (SelectGedrueckt == 1 && zustand == 4)
  {
    SelectGedrueckt = 0;
    zustand = 1;
    lcd.clear();
    lcd.print("Fester Wert");
    lcd.setCursor(0, 1);
    lcd.print("eingestellt");
    delay (2000);
    play = 1;
    playtime();
    delay (200);
  }


  ///////// taster zustand 5 /////

  if (SelectGedrueckt == 1 && zustand == 5)
  {
    analogWrite(green, 0);
    analogWrite(red, 0);
    analogWrite(blue, 255);
    digitalWrite(relais, LOW);
    delay (500);
    lcd.clear();
    lcd.print("Spuelen Stop");
    delay (1000);
    lcd.clear();
    lcd.print("Spuelen Beendet");
    delay (3000);
    zustand = 1;
    analogWrite(blue, 0);
    zustand1();

  }
  if (RunterGedrueckt == 1 && zustand == 5)
  {
    digitalWrite(relais, LOW);
    delay (500);
    lcd.clear();
    lcd.print("Spuelen Stop");
    delay (1000);
    lcd.clear();
    lcd.print("Spuelen Beendet");
    delay (3000);
    zustand = 1;
    zustand1();

  }
  if (HochGedrueckt == 1 && zustand == 5)
  {
    digitalWrite(relais, LOW);
    delay (500);
    lcd.clear();
    lcd.print("Spuelen Stop");
    delay (3000);
    lcd.clear();
    lcd.print("Spuelen Beendet");
    delay (2000);
    zustand = 1;
    zustand1();

  }
  //////////////// taster zustand 6 //////////

  if (HochGedrueckt == 1 && zustand == 6)
  {
    menu6--;
    zustand6();
    delay (200);
  }

  if (RunterGedrueckt == 1 && zustand == 6)
  {
    menu6++;
    zustand6();
    delay (200);
  }

  if (SelectGedrueckt == 1 && zustand == 6)
  {
    fuellangabe = fuellung;
    zustand = 1;
    play = 1;
    playtime();
  }

  // debug print on change:
  static int previousZustand = 42;
  if (zustand != previousZustand)
  {
    Serial.print(F("zustand=")); Serial.println(zustand);
    previousZustand = zustand;
  }
}


void zustand1() {
  Serial.println((__func__));
  /////////////////// zustand 1 /////////////
  switch (menu1)
  {
    case 0:
      menu1 = 1;
      break;
    case 1:
      lcd.clear();
      lcd.print("MENUE");
      lcd.setCursor(0, 1);
      lcd.print(">Spielmodus");
      lcd.setCursor(0, 2);
      lcd.print(" Spuelen");
      lcd.setCursor(0, 3);
      lcd.print(" Fuellangabe");
      break;
    case 2:
      lcd.clear();
      lcd.print("MENUE");
      lcd.setCursor(0, 1);
      lcd.print(" Spielmodus");
      lcd.setCursor(0, 2);
      lcd.print(">Spuelen");
      lcd.setCursor(0, 3);
      lcd.print(" Fuellangabe");
      break;
    case 3:
      lcd.clear();
      lcd.print("MENUE");
      lcd.setCursor(0, 1);
      lcd.print(" Spielmodus");
      lcd.setCursor(0, 2);
      lcd.print(" Spuelen");
      lcd.setCursor(0, 3);
      lcd.print(">Fuellangabe");
      break;
    case 4:
      menu1 = 3;
      break;
  }
}

void zustand2()
/// auswahl zufall / fester wert //// zustand 2 /////////
{
  Serial.println((__func__));
  switch (menu2)
  {
    case 0:
      menu2 = 1;
      break;
    case 1:
      lcd.clear();
      lcd.print("MENUE");
      lcd.setCursor(0, 1);
      lcd.print(">Zufall");
      lcd.setCursor(0, 2);
      lcd.print(" Fester Wert");
      break;
    case 2:
      lcd.clear();
      lcd.print("MENUE");
      lcd.setCursor(0, 1);
      lcd.print(" Zufall");
      lcd.setCursor(0, 2);
      lcd.print(">Fester Wert");
      break;
    case 3:
      menu2 = 1;
      break;
  }
}

void zustand3()
{
  Serial.println((__func__));
  /// zufall genieren ///

  zufallszahl = random(1, 5);
  zufallszahl = random(1, 8);
  zufallszahl = random(1, 10);
  lcd.clear();
  lcd.print("Zufallszahl erstellt");
  vorgabe = zufallszahl;
  delay (1000);
  play = 1;
  playtime();
}


void zustand4()
{
  Serial.println((__func__));
  /// fester wert //
  lcd.clear();
  lcd.print("Fester Wert einstellen");
  lcd.setCursor(0, 1);
  lcd.print("+ / - druecken");
  lcd.setCursor(0, 2);
  lcd.print(vorgabe);
  lcd.print("  ausgewaehlt");
}

void zustand5()
{
  Serial.println((__func__));
  /// spuelen //
  lcd.clear();
  lcd.print("Spuelen startet");
  delay (1000);
  digitalWrite(relais, HIGH);
}

void zustand6()
{
  Serial.println((__func__));
  switch (menu6)
  {
    case 0:
      menu6 = 1;
      break;
    case 1:
      lcd.clear();
      lcd.print("FUELLANGABE");
      lcd.setCursor(0, 1);
      lcd.print(">2 CL");
      lcd.setCursor(0, 2);
      lcd.print(" 1 CL");
      fuellangabe = 2;
      break;
    case 2:
      lcd.clear();
      lcd.print("FUELLANGABE");
      lcd.setCursor(0, 1);
      lcd.print(" 2 CL");
      lcd.setCursor(0, 2);
      lcd.print(">1 CL");
      fuellangabe = 1;
      break;
    case 3:
      menu6 = 2;
      break;
  }
}

void playtime()
{
  Serial.println((__func__));
  stop = 0;
  reedzustand = true;
  reedState = digitalRead(reed);
  if (reedState == HIGH && play == 1 && stop == 0)
  {
    if (reedzustand == true)
    {
      stop = 1;
      analogWrite(green, 0);
      analogWrite(red, 255);
      lcd.clear();
      lcd.print("Bitte oeffnen");
      analogWrite(red, 0);
      analogWrite(red, 255);
      delay (100);
      analogWrite(red, 0);
      delay (100);
      analogWrite(green, 255);
      delay (1000);
      reedzustand = false;
      playtime();
    }
  }
  if (reedState == LOW && play == 1 && stop == 0)
  {
    if (reedzustand == true)
    {
      analogWrite(red, 0);
      analogWrite(green, 255);
      lcd.clear();
      delay (2000);
      play = 2;
      reedzustand = false;
      playtime();
    }
  }
  reedState = digitalRead(reed);
  if (reedState == HIGH && play == 2 && stop == 0)
  {
    if (reedzustand == true)
    {
      stop = 1;
      play = 0;
      schnapp();
      reedzustand = false;
    }
  }
  else {
    playtime();
  }
}

void schnapp()
{
  Serial.println((__func__));
  counter++;
  lcd.clear();
  analogWrite(green, 0);
  analogWrite(red, 255);
  delay (100);
  analogWrite(red, 0);
  delay (100);
  analogWrite(red, 255);
  lcd.print("SCHNAPP!!!");
  lcd.setCursor(0, 1);
  lcd.clear();
  lcd.print("ANZAHL:");
  lcd.setCursor(0, 2);
  lcd.print(counter);
  if (counter == vorgabe)
  {
    analogWrite(blue, 255);
    delay (100);
    analogWrite(blue, 0);
    analogWrite(red, 255);
    delay (100);
    analogWrite(red, 0);
    analogWrite(blue, 255);
    delay (100);
    lcd.clear();
    lcd.print("VERLOREN");
    analogWrite(blue, 0);
    analogWrite(red, 255);
    delay (100);
    analogWrite(red, 0);
    analogWrite(blue, 255);
    delay (100);
    analogWrite(red, 255);
    analogWrite(blue, 0);
    delay (100);
    analogWrite(red, 0);
    analogWrite(blue, 255);
    delay (100);
    analogWrite(blue, 0);
    analogWrite(red, 255);
    delay (100);
    analogWrite(red, 0);
    analogWrite(blue, 255);
    delay (100);
    analogWrite(red, 255);
    analogWrite(blue, 0);
    delay (100);
    analogWrite(red, 0);
    analogWrite(blue, 0);
    delay (3000);
    lcd.clear();
    verloren();
  }
  if (counter != vorgabe)
  {
    delay (3000);
    play = 1;
    playtime();
  }

}

void verloren()
{
  Serial.println((__func__));
  lcd.clear();
  lcd.print("Verloren!");
  analogWrite(green, 0);
  analogWrite(blue, 255);
  analogWrite(red, 0);
  if (fuellung == 1)
  {
    digitalWrite(relais, HIGH);
    delay (3000);
    digitalWrite(relais, LOW);
  }
  if (fuellung == 2)
  {
    digitalWrite(relais, HIGH);
    delay (3000);
    digitalWrite(relais, LOW);
  }
  lcd.clear();
  lcd.print("PROST");
  vorgabe = 0;
  fuellung = 1;
  counter = 0;
  stop = 0;
  zufallszahl = 0;
  analogWrite(blue, 0);
  lcd.clear();

  // testweise
  menu1 = 1;
  zustand = 1;
  fuellung = 1;
  //
  zustand1();
}

ohne einer vernünftigen Beschreibung was dein Programm aber genau machen soll und einem Schaltplan kann ich nicht weiterhelfen.

die variable menu1 setze ich auf 1 kurz vor dem ende (hatte ich beim kopieren vom code nicht eingefügt).
Habe aber gerade gesehen, dass es liegt daran dass ich nicht zustand auf 1 setze.

er geht ja in zustand1, aber reagiert dann nicht auf taster druck.

danke für die schnellen Antworten. werde es heute mittag testen.

Ich hoffe, wenn ich die millis sache noch erledigt habe, dass es recht sauber programmiert ist als Anfänger.
Glaub ich mach es mir an manchen Stellen etwas schwieriger als es ist...

Es fallen halt Code Duplikate auf wie:

if (fuellung == 1)
  {
    digitalWrite(relais, HIGH);
    delay (3000);
    digitalWrite(relais, LOW);
  }
  if (fuellung == 2)
  {
    digitalWrite(relais, HIGH);
    delay (3000);
    digitalWrite(relais, LOW);
  }

warum nicht einfach ein ODER setzen?

if (fuellung == 1 || fuellung == 2)

F-Makro für Fixtexte nutzen,

jeds int prüfen ob es eine vorzeichenbehaftete Variable sein muss oder ob ein anderer Variablentyp besser passt.

Vollständige Fehlermeldungen in der IDE aktivieren und Warnings beheben

STRG-T in der IDE drücken und den Sketch formatieren.

und die Kombination vom blockadefreien Taster lesen (gut) und die Massen an delays (schlecht) im restlichen Code ist halt nicht wirklich logisch.

Kurze Frage zwischendurch:
Wo hast Du die, das, den, der Problem schon einmal gepostet?
Da ist ein Zeitstempel vom 3.12. 17:34 Uhr.

Du hast zum Teil doch schon mit switch/case gearbeitet. Warum hast Du das nicht konsequent gemacht?

Auch Zeiträume berechnenmit millis() machst Du schon.
Von daher verstehe ich Deinen Einwand:

nicht....

Du machst mit einer solchen Frage die Büchse der Pandorra auf.
Warum wird hier stop==0 abgefragt? :roll_eyes:

  stop = 0;
  reedzustand = true;
  reedState = digitalRead(reed);
  if (reedState == HIGH && play == 1 && stop == 0)

Ja.

Ich hab noch nicht mal erfasst, was da wann in welchem Zusammenhang passiert, aber zustand1() ist so ein schickes Beispiel, wie weit das runterzukürzen geht.
Original:

Umgestrickt:

void zustand1()
{
  lcd.clear();
  lcd.print(F("MENUE"));
  lcd.setCursor(1, 1);
  lcd.print(F("Spielmodus"));
  lcd.setCursor(1, 2);
  lcd.print(F("Spuelen"));
  lcd.setCursor(1, 3);
  lcd.print(F("Fuellangabe"));
  if (menu1 == 0)
  { menu1 = 1; }
  else if (menu1 == 4)
  { menu1 = 3; }
  if (menu1 >= 1 && menu1 <= 3)
  {
    lcd.setCursor(0, menu1);
    lcd.print('>');
  }
}

Dabei habe ich noch nicht mal geschaut, was davon wann überhaupt notwendig ist.... Und der untere Teil lässt sich noch weiter kürzen....

Zwei Fragen hätte ich noch:

Wenn ich in Loop() den Zustand des Taster abfrage und dieser gedrückt wird Hochgedrueckt auf 1 gesetzt.
Kann man dann in einem anderen void sowas schreiben ohne irgendwas dazu zu schreiben. Oder macht es Sinn in jedem void den Taster abzurufen?:

void beispiel()
{
if (Hochgedrueckt == 1) {mache dies}
}

Zum Thema Millis:
Wenn ich als Beispiel habe:

analogWrite(green, 0);
analogWrite(red, 255);
delay (100);
 analogWrite(red, 0);
 delay (100);
 analogWrite(red, 255);

Macht es sinn ein void mit millis für die leds extra anzulegen und dieses entsprechend dann an der richtigen stelle auszuführen?

du meinst Funktion.
void vor dem Funktionsnamen bedeutet nur, dass die Funktion keinen Wert zurück gibt. Derartige Funktionen haben kein return (am Ende). Man nennt es aber Funktion (welche halt void - also nichts gültiges zurück liefert.

Ja wenn du öfters diese Kombination brauchst, macht es Sinn eine Funktion zu schreiben.

Hallo,
na klar macht das Sinn.
vermutlich willst Du ja hier einen Blinker haben, schau Dir das Beispile blinkWitoutDelay an. Das kannst Du in eine Funktion packen und die dann aufrufen. Oder Du verwendest eine Rückgabewert als bool.

// psydocode
bool blinkstate; // global

blinkstate=blinker(); // im loop erzeugung eines Blinktaktes 
.
.
digitalWrite(pin1,blinkstate);  // irgendwo im Sketch wenn die LED blinken soll
.
.
digitalWrite(pin2,blinkstate); // ganz woanders im Sketch

oder sowas

digitalWrite( pin,blinker());

das wäre dann einen schöne Übung für Dich wenn Du magst. Wenn Du dann den Blinker öfter brauchst , z.B mit unterschiedliche Frequenzen, langsam schnelles blinken dann könntest Du eine Classe "Blinker" erstellen. Natürlich gibt es sowas auch schon fertig , und sicher hat fast jedes sowas in seiner Bastelkiste.
Heinz

Ich habe es nochmal versucht... Er kommt zwar auf zustand1, aber die taster reagieren trotzdem nicht...
kann es sein, dass Sie nicht reagieren, weil sie halt obendrüber in der loop sind?

Das ist Frage 3.

Kann es sein, das Du nur fragst, aber selbst keine Antworten geben willst?

Im übrigen rufst Du playtime() rekursiv auf.

Hallo marcelnox

Die gemeinsame Verwendung der millis()- und delay() Funktion in einem Sketch ist nicht zu empfehlen.