Thanks for the sugestions. I hadn't put any code because it was very long however I made a simple version to try and explain the problem.
#include <MultitapKeypad.h>
#include <Wire.h>
MultitapKeypad kpd( ROW0, ROW1, ROW2, ROW3, COL0, COL1, COL2, COL3 );
Key key;
int timer_s = 100; // start countdown with 100 seconds
int main_switch = 13; // button to enter code
int main_switch_state = 0; // state on the button
void setup() {
pinMode(main_switch, INPUT);
Timer1.initialize(1000000); // set a timer of length 1000000 microseconds/ 1 sec
Timer1.attachInterrupt( timerIsr );
}
void loop() {
main_switch_state = digitalRead(main_switch);
if (main_switch_state == 0) {
key = kpd.getKey();
// check key and continue
}
}
void timerIsr() {
timer_s -= 1; // decrease countdown by 1 second every time
if (timer_s <= 0) {
Time_out();
}
}
void Time_out() {
// Print on lcd the time is over and spin in an infinite loop
}
When i call the kpd.getKey() function I basicaly have no controll of what hapends and even if i set a flag I can not check it as the program is running in a loop inside the function (part of a libray).
From what I understand I have the folowing options:
- Try to understand the library code and modify it to check a flag. ( would try to avoid if possible as I have tried and ned no succes.
- Try to make my own get.key() function so I have full controll over the code. ( could manage to do that if it was the only option)
- other options????