Can I use kpd.getkey() function inside setup() function for Arduino Mega 2560 R3? I am new to ardunio and I don't have much idea. Basically,my requirement is, I want to switch on an electrical appliance on particular time(SWITCH ON time varies based on a user's input through keypad). Before getting the SWITCH ON time, I am planning to get the CURRENT time . Reason for getting the CURRENT time - I am planning to use the Arduino's inbuilt timer instead of RTC. So, every time when my mom switches on the arduino, she needs to enter the CURRENT TIME and SWITCH ON time for the electric rice cooker.
I am planning to get input twice from keypad using kpd.get() function and provide the value to set time() and Alarm.alarmOnce() functions written inside setup() function respectively. Will this approach work ? Or if you have a ready made sketch, please share. I appreciate your help!
Code:
#include <Time.h> #include <TimeAlarms.h>
#include <kepad.h>
void setup() { Serial.begin(9600);
char key = keypad.getKey();
// Other part of code
setTime(*,*,0,1,11,16); // set CURRENT TIME
Alarm.alarmOnce(*,*,0, switchonApp);
//* Values are obtained from keypad
}
void loop() {
//Other code
}
void switchonApp() {
//Code to switch on the electrical appliance
}