keypad sleep
good afternoon,
i'm learning use sleep modes in arduino, have problem can not solve.
i have arduino, lcd shift register, , keypad.
click on various number , when click on arduino 3 goes sleep.
the problem when wake arduino deletes message screen, keypad not work. click on numbers not appear on screen.
i wonder i'm doing wrong?
i'm learning use sleep modes in arduino, have problem can not solve.
i have arduino, lcd shift register, , keypad.
click on various number , when click on arduino 3 goes sleep.
the problem when wake arduino deletes message screen, keypad not work. click on numbers not appear on screen.
i wonder i'm doing wrong?
quote
#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 row pinouts of keypad
byte colpins[cols] = {12, 11, 10, 9}; //connect column pinouts of keypad
keypad keypad = keypad( makekeymap(keys), rowpins, colpins, rows, cols );
void setup()
{
lcd.begin(16, 2);
//setup 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);
}
the keypad library works polling pins if microcontroller asleep keypad asleep. you'll need wire diodes , connect pins external interrupt. crossroads added hardware interrupt keypad , if scroll down 2 more posts you'll see code go it.
Arduino Forum > Using Arduino > Project Guidance > keypad sleep
arduino
Comments
Post a Comment