alarm clock menu error using switch case

I am trying to build a hay dropping alarm clock for my mules. It doesn’t need to be time accurate, they just need to be fed in the AM and PM. the time part works fine for the most part. but the menus are where I am having trouble.

Im using an osepp lcd 16x2 shield with 5 buttons and a reset on an arduino uno
The analog pins are going to be used to turn on the relay’s needed to drop the hay into the trough.

select is used to navigate the two alarm menus, at the end of the second menu you should go back to the clock, instead it displays

SET ALARM -1
65535:65534SET A

Any help is appreciated. especially tips on how to make the script cleaner and smoother in general. (I am just starting out and eager to learn.)

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

int analogPin = A0;

int key = 0;
int timeout = 0;
unsigned long lastMillisecondrecord = 0;
unsigned long day = 86460000UL; // 86460 sec/day
unsigned long hour = 3600000UL; // 3600 sec/hour
unsigned long minute = 60000UL; // 60 sec/min
unsigned long second = 1000UL; // 1000 millis/sec,
unsigned long alarmtime = 49094017; //alarm time
unsigned long clockTime = 1;
unsigned long timeDifference = 1;
unsigned long lastsecond = 1;
int days = clockTime / day ; //days since reset
int hours = (clockTime % day) / hour; //hours since start of day
int minutes = ((clockTime % day) % hour) / minute ; //minutes since start of hour
int seconds = (((clockTime % day) % hour) % minute) / second; //seconds since start of minute

int alarmdays = alarmtime / day ; //days since reset
int alarmhours = (alarmtime % day) / hour; //hours since start of day
int alarmminutes = ((alarmtime % day) % hour) / minute ; //minutes since start of hour
int alarmseconds = (((alarmtime % day) % hour) % minute) / second; //seconds since start of minute

unsigned long alarm2time = 100000;
int alarm2days = alarm2time / day ; //days since reset
int alarm2hours = (alarm2time % day) / hour; //hours since start of day
int alarm2minutes = ((alarm2time % day) % hour) / minute ; //minutes since start of hour
int alarm2seconds = (((alarm2time % day) % hour) % minute) / second; //seconds since start of minute

int menucount = 0;
int alarmNM = menucount - 1 ;
int alarmIO = {0, 0};
int alarmON = {0, 0};
unsigned int alarmHH = {0, 0};
unsigned int alarmMM = {2, 4};
unsigned int clockTT = {00, 00, 00};
int count = 0;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup()
{
lcd.begin(16,2);
lcd.print(“It’s”);
delay(400);
lcd.print(" a");
delay(400);
lcd.setCursor(0,1);
lcd.print(" beautiful “);
delay(500);
lcd.setCursor(0,0);
lcd.print(” beautiful ");
lcd.setCursor(0,1);
lcd.print("day in the ");
delay(500);
lcd.setCursor(0,0);
lcd.print(“day in the “);
lcd.setCursor(0,1);
lcd.print(” neighborhood”);
delay(1000);
lcd.clear();
}

Here’s another bit

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

switch (menucount) {
case 1:
delay(1);
menu1();
break;
case 2:
delay(1);
menu1();
break;
case 3:
menucount = 0;
delay(1);
break;
case 4:
menucount = 0;
delay(1);
break;
case 5:
menucount = 0;
delay (1);
break;
default**:**
{

key = analogRead(A0);
unsigned long currentMillisecond = millis();
if(millis() >= 4294967292){ //rollover actually happens at 4294967295, the clock will hang for 3ms
currentMillisecond = 0;
lastMillisecondrecord = 0;
}
timeDifference = currentMillisecond - lastMillisecondrecord;
lastMillisecondrecord = currentMillisecond;
clockTime = clockTime + timeDifference; /measures the difference in millis between the last time millis was recorded
then it adds it to the clockTime integer
/

//if(clockTime >= 86460000){ //resets the clock after a week of running [to allow weekend function, although I might not use it right now]
//clockTime = 0;
//}
int days = clockTime / day ; //days since reset
int hours = (clockTime % day) / hour; //hours since start of day
int minutes = ((clockTime % day) % hour) / minute ; //minutes since start of hour
int seconds = (((clockTime % day) % hour) % minute) / second; //seconds since start of minute

int alarmdays = alarmtime / day ; //days since reset
int alarmhours = (alarmtime % day) / hour; //hours since start of day
int alarmminutes = ((alarmtime % day) % hour) / minute ; //minutes since start of hour
int alarmseconds = (((alarmtime % day) % hour) % minute) / second; //seconds since start of minute

clockTT [ 0 ] = hours;
clockTT [ 1 ] = minutes;
clockTT [ 2 ] = seconds;
//////////////////////////////////////////////////print the time
lcd.setCursor(0,0);
lcd.print(“Time: “);
lcd.setCursor(0,1);
if(clockTT[0] < 10){lcd.print(‘0’);};
lcd.print(clockTT[0]);
lcd.print(”:”);
if(clockTT[1] < 10){lcd.print(‘0’);};
lcd.print(clockTT[1]);
lcd.print(":");
if(clockTT[2] < 10){lcd.print(‘0’);};
lcd.print(clockTT[2]);

///////////////////////////////////alarmcheck
if(clockTT[0] == alarmHH[count]){
if(clockTT[1] == alarmMM[count]){
lcd.setCursor(0,0);
alarm();

}
}

count++; //increment count to check other alarms, I only needed two for this project, but the board has 5 unused analog ports you could use.
if(count > 1){
count = 0;

/////////////////////////////////////////////////////////////////////////////////////////////////////homebuttons

////////////////////////////////////////////////////////////////////////////////////////////////////
key = analogRead(A0);
switch (key) {
case 0: //RIGHT
lcd.clear();
menucount = 1;
delay(200);
break;
case 100: //UP
timeout = 0;
clockTime = clockTime + hour;
delay(200);
break;
case 256: //DOWN
timeout = 0;
clockTime = clockTime - hour;
delay(200);
break;
case 640: //SELECT
menucount++;
delay(100);
break;
case 410: //LEFT
timeout = 0;
clockTime = clockTime + hour;
delay (200);
break;
default:
timeout = 0;
break;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////
}}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////clocktime
break;

lcd.setCursor(0,0);
}

} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////endofloop

void alarm(){
switch(count){
case 0:

pinMode(A1, OUTPUT);
digitalWrite(A1, HIGH);
lcd.print(“Alarm 1”); //Alarm 1 is case 0: because arduino arrays are ZERO indexed
delay (1000);
digitalWrite(A1, LOW);
// delay (51000);
lcd.clear();
break;

case 1:
pinMode(A2, OUTPUT);
digitalWrite(A2, HIGH);
lcd.print(“Alarm 2”);
delay (1000); //set to 10000 or larger before use
digitalWrite(A2, LOW);
// delay (51000); //enable this delay before use
lcd.clear();
break;

}

}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void menu1()
{
key = analogRead(A0);
switch (key) {

case 0: //RIGHT
alarmMM[alarmNM]++;
lcd.setCursor(0,1);

if (alarmHH[alarmNM] < 10){
lcd.print(“0”);}
lcd.print ((alarmHH[alarmNM]));
lcd.print(":");

if (alarmMM[alarmNM] < 10){
lcd.print(“0”);}

lcd.print ((alarmMM[alarmNM]));

delay(150);
break;

case 100: //UP
alarmHH[alarmNM]++;
lcd.setCursor(0,1);

if (alarmHH[alarmNM] < 10){
lcd.print(“0”);}
lcd.print ((alarmHH[alarmNM]));
lcd.print(":");

if (alarmMM[alarmNM] < 10){
lcd.print(“0”);}

lcd.print ((alarmMM[alarmNM]));

delay(150);
break;

case 256: //DOWN
alarmHH[alarmNM]–;
lcd.setCursor(0,1);

if (alarmHH[alarmNM] < 10){
lcd.print(“0”);}
lcd.print ((alarmHH[alarmNM]));
lcd.print(":");

if (alarmMM[alarmNM] < 10){
lcd.print(“0”);}

lcd.print ((alarmMM[alarmNM]));

delay(150);
break;

case 410: //LEFT
alarmMM[alarmNM]–;
lcd.setCursor(0,1);

if (alarmHH[alarmNM] < 10){
lcd.print(“0”);}
lcd.print ((alarmHH[alarmNM]));
lcd.print(":");

if (alarmMM[alarmNM] < 10){
lcd.print(“0”);}

lcd.print ((alarmMM[alarmNM]));

delay(50);
break;

case 640: //SELECT
lcd.clear();
menucount++;
alarmNM++;
delay(200);
if(alarmNM > 1){
alarmNM = -1;

}
{
lcd.setCursor(0,0);
if(alarmNM == -1){
lcd.clear();
loop();
}
lcd.print ("SET ALARM ");
lcd.print (alarmNM);

lcd.setCursor(0,1);

if (alarmHH[alarmNM] < 10){
lcd.print(“0”);}
lcd.print ((alarmHH[alarmNM]));
lcd.print(":");

if (alarmMM[alarmNM] < 10){
lcd.print(“0”);}

lcd.print ((alarmMM[alarmNM]));

}

delay (100);

break;

default:
{
lcd.setCursor(0,0);
lcd.print ("SET ALARM ");
lcd.print (alarmNM);

lcd.setCursor(0,1);

if (alarmHH[alarmNM] < 10){
lcd.print(“0”);}
lcd.print ((alarmHH[alarmNM]));
lcd.print(":");

if (alarmMM[alarmNM] < 10){
lcd.print(“0”);}

lcd.print ((alarmMM[alarmNM]));

}
break;
}
}

If the code is too big to post between code tags, please attach it to the post instead.

key = analogRead(A0);
switch (key) {
  case 0: //RIGHT
    lcd.clear();
  menucount = 1;
    delay(200);
    break;
  case 100: //UP

Noise on any analogRead means you are almost never going to be able to select anything in the menu.
Try case 100 ... 199: or similar, or use "if/else" with the "abs"