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() { // Empty loop }
The SLEEP_MODE_POWER_DOWN mode puts the Arduino into the lowest power state, reducing power consumption significantly.
Complete the code to disable the ADC to save power.
void setup() {
ADCSRA [1] 0;
}
void loop() {
// Main code
}Using = 0 disables all bits in the ADCSRA register, turning off the ADC to save power.
Fix the error in the code to turn off the built-in LED to save power.
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, [1]);
}
void loop() {
// Empty loop
}Setting the LED pin to LOW turns off the LED, reducing power consumption.
Fill both blanks to create a dictionary of sensor readings only if the reading is above 100.
int readings[] = {120, 90, 150, 80};
void setup() {
Serial.begin(9600);
for (int i = 0; i < 4; i++) {
if (readings[i] [1] 100) {
Serial.println(readings[i] [2] 2);
}
}
}
void loop() {}The condition readings[i] > 100 filters readings above 100. Multiplying by 2 doubles the value before printing.
Fill all three blanks to create a map of sensor names to values only if the value is positive.
String sensors[] = {"temp", "light", "sound"};
int values[] = {25, -5, 10};
void setup() {
Serial.begin(9600);
for (int i = 0; i < 3; i++) {
if (values[i] [3] 0) {
Serial.print(sensors[i].[1]());
Serial.print(": ");
Serial.println(values[i] [2] 1);
}
}
}
void loop() {}The condition values[i] > 0 filters positive values. Using toLowerCase() converts sensor names to lowercase. Multiplying by 1 keeps the value unchanged.