Hi,
I am having some strange problems with my interrupt I am trying to get to work. I have attached a 4X4 keypad that wakes the arduino when it is aslepp by pressing a button. So fine, everything is working and the keypress puts my project into "Programming" mode.
The strange thing is that when the arduino wakes up, it seems like the interrupt gets triggered? The result is that it is being forced into my "programming" mode again?
Any suggestions? This is the first time I am trying to solve this so please be patient
#include <LowPower.h>
#include <Keypad.h>
// ---------------------------------
// KEPAD DEFINITIONS AND VARIABLES
// ---------------------------------
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {10, 9, 8 , 7}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6, 5, 4, 3}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
// ---------------------------------
//VARIABLES
// ---------------------------------
//Programming variables
boolean enterProgramming = false;
boolean isWaked = false;
char key;
//Interupt / sleep
int wakePin = 2;
void setup()
{
Serial.begin(115200);
Serial.println("Starting up....");
delay(1000);
pinMode(wakePin, INPUT);
}
void loop()
{
//First check if we are getting a keystroke to enter programming mode
key = keypad.getKey();
delay(100);
String Temp;
// Arduino is been waked up by the key press - now enter programming mode!
if(isWaked==true){
enterProgramming = true;
isWaked = false;
Serial.println("");
Serial.println("Entering programming mode");
delay(500);
}
if (enterProgramming==true){
//We are in programming mode
if(key == 'A'){ //Jumps out of programming mode and goes to "work" mode.
enterProgramming=false;
Serial.println("");
Serial.println("Exiting programming mode");
}
else
{
Serial.println(key);
}
}else{
//enterProgramming = false;
}
// Main loop when we are not in programming mode - just our work mode.
if(enterProgramming==false){
delay(500);
Serial.println("Running mode");
attachInterrupt(0,wakeUpNow, HIGH);
delay(100);
Serial.println("Going to sleep...");
delay(100);
// Kör sleep koden
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
delay(100);
Serial.println("Sleep is over...");
delay(200);
detachInterrupt(0);
}
}
void wakeUpNow() {
isWaked = true;
}