Consider this Arduino code that blinks an LED connected to pin 13. What will be printed on the Serial Monitor?
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
Serial.println("LED ON");
delay(1000);
digitalWrite(13, LOW);
Serial.println("LED OFF");
delay(1000);
}Look at the Serial.println calls inside the loop() function.
The code prints "LED ON" then "LED OFF" every second because the loop() runs repeatedly, toggling the LED and printing the status each time.
Which of the following is the best reason to split Arduino code into multiple files (like separate .ino or .h/.cpp files)?
Think about how organizing papers in folders helps you find things faster.
Splitting code into files groups related parts together, making it easier to read, debug, and update. It does not affect speed or size directly.
Look at this Arduino sketch split into two files. Why does it fail to compile?
// File: main.ino
#include "led_control.h"
void setup() {
initLED();
}
void loop() {
toggleLED();
delay(500);
}
// File: led_control.h
void initLED();
void toggleLED();
// File: led_control.cpp
#include
void initLED() {
pinMode(13, OUTPUT);
}
void toggleLED() {
static bool state = false;
state = !state;
digitalWrite(13, state);
}
Check if all files are included and compiled by the Arduino IDE.
If led_control.cpp is not added to the project or compiled, the linker cannot find the function definitions, causing a compile error.
Which of these code snippets will cause a syntax error when compiling an Arduino sketch?
Look carefully for missing semicolons.
Option A is missing a semicolon after pinMode(13, OUTPUT), causing a syntax error.
Given this Arduino project with three files, how many unique functions are defined?
// main.ino
#include "sensor.h"
#include "display.h"
void setup() {
initSensor();
initDisplay();
}
void loop() {
int value = readSensor();
showValue(value);
delay(1000);
}
// sensor.h
void initSensor();
int readSensor();
// sensor.cpp
#include
void initSensor() { /* setup sensor pins */ }
int readSensor() { return analogRead(A0); }
// display.h
void initDisplay();
void showValue(int val);
// display.cpp
#include
void initDisplay() { /* setup display */ }
void showValue(int val) { /* display val */ }
Count all unique function definitions across all files.
Functions defined are: initSensor, readSensor, initDisplay, showValue — total 4.