9.10.6 Port PinsWhen entering a sleep mode, all port pins should be configured to use minimum power. Themost important is then to ensure that no pins drive resistive loads. In sleep modes where boththe I/O clock (clkI/O) and the ADC clock (clkADC) are stopped, the input buffers of the device willbe disabled. This ensures that no power is consumed by the input logic when not needed. Insome cases, the input logic is needed for detecting wake-up conditions, and it will then beenabled. Refer to the section "Digital Input Enable and Sleep Modes" on page 80 for details onwhich pins are enabled. If the input buffer is enabled and the input signal is left floating or havean analog signal level close to VCC/2, the input buffer will use excessive power.
13.2.5 Digital Input Enable and Sleep ModesAs shown in Figure 13-2, the digital input signal can be clamped to ground at the input of theSchmitt Trigger. The signal denoted SLEEP in the figure, is set by the MCU Sleep Controller inPower-down mode, Power-save mode, and Standby mode to avoid high power consumption ifsome input signals are left floating, or have an analog signal level close to VCC/2.SLEEP is overridden for port pins enabled as external interrupt pins. If the external interruptrequest is not enabled, SLEEP is active also for these pins. SLEEP is also overridden by variousother alternate functions as described in "Alternate Port Functions" on page 81.
Serial.println("Entering sleep."); // try setting kepyad columns low before sleeping digitalWrite(7, LOW); digitalWrite(8, LOW); digitalWrite(9, LOW); digitalWrite(10, LOW); delay(200); enterSleep(); // THE PROGRAM CONTINUEs FROM HERE after waking up in enterSleep() Serial.println("recovered from sleep.");
sleep_mode(); /* The program will continue from here after the interrupt. */ /* First thing to do is disable sleep. */ sleep_disable(); //Serial.println("waking up."); // set the keypad columns back high - need all of them set // or only get key presses in the column that is high digitalWrite(7, HIGH); digitalWrite(8, HIGH); digitalWrite(9, HIGH); digitalWrite(10, HIGH); // then go to the void Loop()