lcd displaying errors

good day

please assist, I am working on a small project that uses a keypad to enter a letter, once a letter is entered its allow the user to enter one number from 1 to 25. once the number is entered its allow the user to enter number from 1 to 6 which represent different jobs, once the number is entered its allow the user to enter a value which is time in minutes which its will take to complete the job. its then start counting till its reach the time value then an led comes on which is cleared by the user.

my problem is when i am diving millis by 1000 the program works fine for every value of time i enter, but when i have divided millis by 60000 its work well for numbers 1 to 9 as soon as I enter time as 10 min and above, its count to that value then instead of turning on the led the screen goes to error displaying unkown laungage

// THIS CODE ALLOW THE USER TO ENTER ANY NUMBER FROM 1 T0 25.
// AFTER INPUTTING THE VALUE BETWEEN THE RANGE ITS ALLOW THE USER TO SELECT ANY VALUE BETWEEN 1 T0 6
//THEN AFTER ALLOWING THE USER TO ENTER ANY VALUE REQUIRED BY THE USER
// ITS START TIMING THE COMPARING THE VALUE TO THE ONCE REQUIRED BY THE USER

sketch_oct29a.ino (13.1 KB)

Briefly looking at your code... You are using 'int' type for mac1, mac2, etc. which can only hold up to 32767. You need to have the correct sized variables for what you are doing.

Also, code like this

int math()
{
  customKey = keypad.waitForKey();
  if (customKey == '*') {
    previousMillis = millis() / 1000;

  }
  else math();
}

Is recursive and will eventually overflow your arduino. You do this several times. (mathA, mathB, etc.)

I am aware of that but i want to get the program working first of which its not then I can sort that out

No, you should start by doing thing correctly at a very basic level and then build up your code to do all you want. Dividing something by 60000 requires 'long int' or 'unsigned long int'

Blue10:
I am aware of that but i want to get the program working first of which its not then I can sort that out

Write a small test program to see what goes wrong. Use serial print/ln statements and the serial monitor to see what goes wrong.

blh64:
Briefly looking at your code... You are using 'int' type for mac1, mac2, etc. which can only hold up to 32767. You need to have the correct sized variables for what you are doing.

Also, code like this

int math()

{
  customKey = keypad.waitForKey();
  if (customKey == '*') {
    previousMillis = millis() / 1000;

}
  else math();
}



Is recursive and will eventually overflow your arduino. You do this several times. (mathA, mathB, etc.)

Actually, unless you are really really fast at pressing that button this will overflow things really fast, not eventually. There is a function that will wait for a key. Use that instead.

Blue10:
I am aware of that but i want to get the program working first of which its not then I can sort that out

Sorting that will be the first step of getting this to work. It's not going to work out with runaway recursion. Unless you are a pro who really really knows what they're doing you shouldn't ever have a function calling itself.

when I a, dividing by 1000 the program works perfect for every number I enter. the problem is when I am dividig by 60000 the program works perfect for number 1 to 13 but as soon as the numbers is about 13 its count up to that number then its reset its self to the start of the program istead of waiting for the key to be pressed to cancel the alarm

int math()
{
customKey = keypad.waitForKey();
if (customKey == '*') {
previousMillis = millis() / 1000;

}
else math();
}

then its reset its self to the start of the program istead of waiting for the key to be pressed to cancel the alarm

Typical behaviour when the processor runs out of memory (RAM). And the processor runs out of memory due to recursion.

Blue10:
when I a, dividing by 1000 the program works perfect for every number I enter. the problem is when I am dividig by 60000 the program works perfect for number 1 to 13 but as soon as the numbers is about 13 its count up to that number then its reset its self to the start of the program istead of waiting for the key to be pressed to cancel the alarm

int math()
{
customKey = keypad.waitForKey();
if (customKey == ‘*’) {
previousMillis = millis() / 1000;

}
else math();
}

You’ve already been told the reason for both. Why are you asking the same thing again with more improperly posted code?

You have recursion all over the place; as advised, get rid of it.

Nearly all your functions are supposed to return an integer but most of them don’t. Let them return a value and make use of that value to indicate that you can continue or not.

Simple example for math(); change the function declaration to return a bool.

bool math()
{
  customKey = keypad.waitForKey();
  if (customKey == '*')
  {
    previousMillis = millis() / 1000;
    return true;
  }
  else
  {
    return false;
  }
}

and where you currently call math(), change it to

while(math() != true)
{
  // do nothing
}

I think that you can apply this principle about everywhere where you currently use recursion. You might want to return what is needed.

Next you have functions that do ecactly the same thing except for assigning user input to another variable. E.g. the Minutes() and MinutesX() functions. That can be done in one function if you let the function return the user input. I’m not sure of the maximum value that the user can enter and I don’t understand why Value, Values and Valuess are floats; hence I changed the return type to float. If you don’t need float variables, change it to int or long.

float Minutes()
{
  int customKey;
  int isnum;

  lcd.print("ENTER TIME: ");
  lcd.setCursor(0, 1);

  float val = 0;

  do
  {
    customKey = keypad.getKey();
    isnum = (customKey >= '0' && customKey <= '9');
    if (isnum)
    {
      lcd.print(customKey - '0');
      val = val * 10 + customKey - '0';
    }

  } while (isnum || !customKey);

  lcd.print(" ");

  return val;

}

Now everywhere where you call one of those Minutes() / MinutesX() functions, you can use

Value = Minutes();
or
Values = Minutes();

Above are some steps to get you on the way. As suggested in reply #3, start from scratch.