I have been trying to create a program that awakens the board from low power state. There is a lot written about this subject but I could not implement it because I could not get the interrupts to work properly.
I tried just copying and pasting the simple blinking LED light interrupt program on the arduino site but found that it does not work either.
I wrote a simple program that triggers the arduino to go in and out of low power mode when a button is pushed. I can get the arduino to enter sleep mode but can not awaken it with the interrupt.
#include <Keypad.h>
#include <avr/sleep.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 3, 2}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
Serial.begin(9600);
Serial.println("Start");
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
}
void blink_isr() {
detachInterrupt(digitalPinToInterrupt(2));
sleep_disable();
}
void goToSleep() {
Serial.print("gotosleep");
sleep_enable();
attachInterrupt(digitalPinToInterrupt(2), blink_isr, RISING);
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
digitalWrite(13, HIGH);
sleep_mode();
/* wake up here */
sleep_disable();
digitalWrite(13, LOW);
}
void loop() {
char key = keypad.getKey();
if (key == '#') {
goToSleep();
}
}
keypad interrupt.txt (1.05 KB)