Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to set the LED pin as output in setup().
Arduino
void setup() {
pinMode([1], OUTPUT);
}
void loop() {
// blinking code here
}Attempts:
3 left
💡 Hint
Common Mistakes
Using a pin number directly without knowing if it matches the built-in LED.
Forgetting to set the pin mode to OUTPUT.
✗ Incorrect
The built-in LED pin is usually defined as LED_BUILTIN, which is pin 13 on most Arduino boards.
2fill in blank
mediumComplete the code to get the current time in milliseconds inside loop().
Arduino
void loop() {
unsigned long currentMillis = [1]();
// rest of the code
}Attempts:
3 left
💡 Hint
Common Mistakes
Using delay() which pauses the program.
Using micros() which returns microseconds, not milliseconds.
✗ Incorrect
The millis() function returns the number of milliseconds since the Arduino started running the current program.
3fill in blank
hardFix the error in the if condition to check if the interval has passed.
Arduino
if (currentMillis - previousMillis [1] interval) { // toggle LED }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' which triggers too early.
Using '==' which may miss the exact match.
✗ Incorrect
We check if the time difference is greater than or equal to the interval to know when to toggle the LED.
4fill in blank
hardFill both blanks to toggle the LED state and update previousMillis.
Arduino
if (ledState == LOW) { ledState = [1]; } else { ledState = [2]; } previousMillis = currentMillis;
Attempts:
3 left
💡 Hint
Common Mistakes
Using boolean true/false instead of HIGH/LOW.
Setting both states to the same value.
✗ Incorrect
If the LED is off (LOW), turn it on (HIGH). Otherwise, turn it off (LOW).
5fill in blank
hardFill all three blanks to complete the blink without delay pattern code.
Arduino
const int ledPin = [1]; unsigned long previousMillis = 0; const long interval = [2]; int ledState = LOW; void setup() { pinMode(ledPin, OUTPUT); } void loop() { unsigned long currentMillis = [3](); if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis; if (ledState == LOW) { ledState = HIGH; } else { ledState = LOW; } digitalWrite(ledPin, ledState); } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using delay() instead of millis().
Using wrong pin number instead of LED_BUILTIN.
Setting interval to 1 instead of 1000.
✗ Incorrect
Use LED_BUILTIN for the built-in LED pin, 1000 milliseconds for 1 second interval, and millis() to get current time.
