Complete the code to put the Arduino into sleep mode.
#include <avr/sleep.h> void setup() { Serial.begin(9600); set_sleep_mode([1]); sleep_enable(); sleep_cpu(); } void loop() { // Nothing here }
The SLEEP_MODE_PWR_DOWN mode puts the Arduino into the deepest sleep, saving the most power.
Complete the code to disable sleep mode after waking up.
void wakeUp() {
sleep_disable();
Serial.println("Woke up!");
}
void setup() {
attachInterrupt(digitalPinToInterrupt(2), wakeUp, [1]);
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sleep_cpu();
}
void loop() {
// Sleep until interrupt
}LOW, which triggers continuously while the pin is held low.The interrupt triggers on a rising edge signal, waking the Arduino from sleep.
Fix the error in the code to correctly enter sleep mode.
#include <avr/sleep.h> void setup() { Serial.begin(9600); set_sleep_mode(SLEEP_MODE_PWR_DOWN); [1](); sleep_cpu(); } void loop() { // Sleep here }
sleep_disable() instead of sleep_enable().You must call sleep_enable() before sleep_cpu() to activate sleep mode.
Fill both blanks to create a dictionary of sleep modes and their descriptions.
const char* sleepModes[] = {"[1]", "[2]"};
void setup() {
Serial.begin(9600);
Serial.println(sleepModes[0]);
Serial.println(sleepModes[1]);
}
void loop() {}The array holds the mode name and its description. Here, SLEEP_MODE_IDLE and "Idle mode" are paired.
Fill all three blanks to create a function that sets sleep mode and enters sleep.
void enterSleepMode([1] mode) { set_sleep_mode([2]); [3](); sleep_cpu(); } void setup() { Serial.begin(9600); enterSleepMode(SLEEP_MODE_PWR_DOWN); } void loop() {}
The function takes an integer mode, sets it as the sleep mode, enables sleep, then enters sleep.