Hi. I have a little problem with my atmega. I'm trying to make a module for a car - so I need power saving. This module uses the switch from the car with two states LOW and HIGH. When the signal is HIGH, the module shuts down and enters sleep mode. But when the button changes state my atmega doesn't wake up.
SW: HIGH -> ATMEGA goes to sleep.
SW: LOW -> ATMEGA wake up.
i don't know what i'm doing wrong... Maybe with digital pin it's impossible?
Code fragment:
#define WAKE_UP_PIN 6
void SleepModule(){
attachInterrupt(WAKE_UP_PIN, wakeUp, LOW);
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
detachInterrupt(WAKE_UP_PIN);
// old code
return;
if(disableSleep) return;
static byte prevADCSRA = ADCSRA;
ADCSRA = 0;
set_sleep_mode (SLEEP_MODE_PWR_DOWN);
sleep_enable();
MCUCR = bit (BODS) | bit (BODSE);
MCUCR = bit (BODS);
noInterrupts();
// attachInterrupt(WAKE_UP_PIN, wakeUp, LOW);
// Allow interrupts now
interrupts();
// And enter sleep mode as set above
sleep_cpu();
// Re-enable ADC if it was previously running
ADCSRA = prevADCSRA;
}
void wakeUp() {
MOTOR_FORWARD();
}
void setup() {
pinMode(WAKE_UP_PIN, INPUT);
}
void loop(){
if(digitalRead(WAKE_UP_PIN) == HIGH)
SleepModule();
}
P.S I have external pins pulluped for high state, so I don't need pull up from atmega.
I observe module's sleeping by multimetr and watching current, so I don't need more code for tests.