Good afternoon,
I'm learning to use sleep modes in arduino, but I have a problem I can not solve.
I have arduino, lcd shift register, and keypad.
Click on various number and when I click on the arduino 3 goes into sleep.
The problem is when I wake the Arduino it deletes the message from the screen, but the keypad does not work. I click on the numbers but does not appear on any screen.
I wonder what I'm doing wrong?
#include <ShiftLCD.h>
#include <Keypad.h>
#include <avr/power.h>
#include <avr/sleep.h>
int wakePin = 2;ShiftLCD lcd(19, 17, 18);
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'D','#','0','*'},
{'C','9','8','7'},
{'B','6','5','4'},
{'A','3','2','1'},
};
byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {12, 11, 10, 9}; //connect to the column pinouts of the keypadKeypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
lcd.begin(16, 2);
//setup the pushbutoon
pinMode(wakePin, INPUT);
digitalWrite(wakePin, HIGH);attachInterrupt(0, wakeUpNow, LOW);
}
void loop()
{
char key = keypad.getKey();if (key!= NO_KEY){
lcd.print(key);
if (key == '3' ){
sleepNow();
}
}
}void wakeUpNow()
{
lcd.clear();}
void sleepNow()
{
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sleep_cpu ();
attachInterrupt(0,wakeUpNow, LOW);
sleep_mode();
sleep_disable();
detachInterrupt(0);}