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 ++;
}
}
}
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)
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';
}
}
}
}
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?
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??