Complete the code to turn on the built-in LED on an Arduino board.
void setup() {
pinMode(LED_BUILTIN, [1]);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}The pinMode function sets the mode of a pin. To turn on an LED, the pin must be set as OUTPUT.
Complete the code to read the value from a sensor connected to analog pin A0.
int sensorValue = analogRead([1]);The analogRead function reads the value from an analog pin. The sensor is connected to pin A0.
Fix the error in the code to blink an LED every second.
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay([1]);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}The delay function pauses the program for the given milliseconds. To blink every second, both delays should be 1000 ms.
Fill both blanks to create a dictionary of sensor readings where keys are sensor names and values are their readings.
int sensor1 = analogRead(A0);
int sensor2 = analogRead(A1);
int readings[] = {sensor1, sensor2};
String sensors[] = {"temp", "light"};
for (int [1] = 0; [1] < 2; [1]++) {
Serial.print(sensors[[2]]);
Serial.print(": ");
Serial.println(readings[[1]]);
}The loop variable i is used to access both arrays for keys and values.
Fill all three blanks to define a function that reads a sensor value and returns true if it is above a threshold.
bool isHigh(int [1], int [2]) { int value = analogRead([3]); return value > [2]; }
The function takes pin and threshold as parameters. It reads the sensor on pin and compares it to threshold.
