declaration ++;

i think i have a mistake in my code. can someone help me with this… i’m trying to input two or more numbers in the ‘Sec’ after pressing the ‘’ key to send it to Serial but its function was not that good. the ‘#’ continues to appear in serial and it does not read my inputted value in the keypad. here is an example…
when this function is called first it will wait 5 sec before it returns to the loop section but when i enter any number (for example 25) from the keypad, it will store the numbers to ‘Sec’ so that when i pressed the '
’ key. it will be moved to Alarm.timerRepeat(Sec, OnlyOnce); so that ‘Sec’ will be replaced as 25. am i clear?? or do i am in the correct path?

void setAlarm()
{
//    Serial.println("Format should be: SS");
    Serial.println("Set Second Timer:");
while ( (unsigned long)(millis() - timeRef) < 5000 )
  {
  if (key != KEY_NOT_PRESSED)
  {
//      Serial.println(key);  }  
    if (key == '*'){
      Alarm.timerRepeat(Sec, OnlyOnce);
      Serial.print(Sec);
      Serial.print("Working n ata!!");
      Sec = 0;
    }
    else if (key == '#'){delay(1000);}
    else
    {
     key = Sec;
     Sec ++;
    }
  }
}

thank you.!

As i understand it, you want to add any number you type in the keypad to the Sec variable, until you hit the * button . Am i right?

What data type have you used for Sec and key variables?

I think what you want is:

    {
     // key = Sec;
     // Sec ++;
    Sec = Sec * 10 + key - '0';
    }

@connduino
i used char for key and byte for Sec…

@johnwasser
sir can you explain how do it comes up with that equation?? wny do i need to muliply it by 10?

sir can you explain how do it comes up with that equation?? wny do i need to muliply it by 10?

Suppose that the first key you press results in '4'. Suppose that the second key you press results in '8'.

What value do you expect? Do the math yourself to understand why the equation MUST be that way.

ok. thanks.. my fault. i misunderstand the formula. but, do i don't need to declare the key = Sec and Sec ++;

but, do i don't need to declare the key = Sec and Sec ++;

Why would you? Isn't key the variable that is valued when a key is pressed? Assigning it another value before using the pressed key value doesn't make sense. The value of the pressed key is used to define the new value TO BE USED for Sec (when the appropriate "I'm done" event occurs).

thanks alot. its working already. next is i want to enter the whole time to be set. (e.g. Alarm.timerRepeat(wholeTime, OnlyOnce):wink:
and wholeTime should be equal to HH,MM,SS. any suggestion on how do i enter these digits from keypad in simple codes? i need to minimise the codes because theres a lot more to be added but there is almost 32kb only the arduino can handle…
is my explanation is clear?thanks…

any suggestion on how do i enter these digits from keypad in simple codes?

Create a function to get a 2 digit value. Call that function to get the hours. Call it again to get the minutes. Call it a third time to get the seconds.

kindly help? i am trying to enter Hr and Min so that it can be placed on the timer but i`m having trouble on the process… it end after pressing * key after inputting the value of hour but i also need to enter the Min timer. is there any code that can ease this process or to fix this…

void SetTime()
{
  Serial.println("Set Time to:");
  Serial.print("Enter Hour (24 Hour format): ");
while ((unsigned long)(millis() - timeRef) < 5000 )
  {
    char key = keyVal.readKey();
    if (key != KEY_NOT_PRESSED)
    { 
      if (key == '*'){
        Serial.println("Enter Minutes:");
        // Sets the Minutes
        if (key == '#') {
           Serial.print("Operation Cancelled!");
           digitalClockDisplay();
           }
        if (key == '*') {
          data = Hr+ ','+ Min;
          Alarm.write(onTime, data);
          Serial.print("Alarm was set to: ");
          Serial.println(Hr+':'+Min);
          Min = 0;
          Hr = 0;
          Alarm.enable(onTime);
          digitalClockDisplay();
          }
        else {
          Min = Min * 10 + key - '0';
          }
        }
      else if (key == '#') {
        Serial.println("Operation Cancelled");
        digitalClockDisplay();
       }
      else
      {    
        Hr = Hr * 10 + key - '0';
      }
    }
  }
}

Thank you…

You need to spend a little more time studying code. Here’s a start:

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

void loop() {
  int charsReceived;
  char buffer[10];
   
  if (Serial.available() > 0) {
    charsReceived = Serial.readBytesUntil('\n', buffer, 9);
    buffer[charsReceived] = '\0';
    Serial.println(buffer);
  }
}

Type in “12:34:56” into the Serial monitor and click Send. Once you understand what this code does, then read up on strchr() or strtok().

      if (key == '*'){
        Serial.println("Enter Minutes:");
        // Sets the Minutes
        if (key == '#') {

If the value in key is '*', what are the odds that the value in key is '#'?

Not a snowball's chance in hell, I'd think. YMMV.

ellinnaj04:
@johnwasser
sir can you explain how do it comes up with that equation?? wny do i need to muliply it by 10?

Do you want to sum the numbers (4 + 8 = 12) or concatenate them (4 + 8 = 48) ?

just (4+8 = 48)..

for example.. when i pressed this keys '1530' in keypad let say key = keypad.read so that is key will be equal to 1530 right?? can i seperate that values into 2?? for example Hr will be equal to '15' and Min will be equal to '30' is it possible?? and how?

The first two numbers for the hour and the next two numbers for the minutes.

yup. how can i separate those 4digits into Two 2digits variable.. or any other way to get that 4 digits??

yup. how can i separate those 4digits into Two 2digits variable.. or any other way to get that 4 digits??

You "get" the digits one at a time. There is no need to separate them. The first time you get a digit, store it in hour. The next time you get a digit, multiply hour by 10 and add the new digit. Next time, store the value in minute.

sir, how can i limit the amount of value in setting the Hr?? for example, maximum value of hours should be 23 but using keypad. it accepts 24 and above. how can i disable it??

Test the value entered and restart the entry process if it is greater than 23.

can u make an sample code?? thanks..