Complete the code to initialize TimerOne with a 1-second interval.
#include <TimerOne.h> void setup() { TimerOne.[1](1000000); // 1 second interval } void loop() { // main code }
start() instead of setPeriod().initialize() which is not a TimerOne function.The setPeriod function sets the timer interval in microseconds.
Complete the code to attach an interrupt service routine named blinkLED.
void setup() {
TimerOne.setPeriod(500000); // 0.5 second
TimerOne.[1](blinkLED);
}
void blinkLED() {
// toggle LED
}start() which only starts the timer.setInterrupt() which is not a TimerOne method.The attachInterrupt function links the timer to the ISR function.
Fix the error in the code to start the timer after setting the period and ISR.
void setup() {
TimerOne.setPeriod(2000000); // 2 seconds
TimerOne.attachInterrupt(blinkLED);
TimerOne.[1]();
}
void blinkLED() {
// toggle LED
}begin() which is not a TimerOne method.enable() or run() which do not exist.The start() function starts the timer counting.
Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.
String words[] = {"apple", "bat", "carrot", "dog"};
int lengths[4] = {0};
for (int i = 0; i < 4; i++) {
if (words[i].length() [1] 3) {
lengths[i] = words[i].[2]();
}
}< instead of > in the if condition.size() which is not a String method in Arduino.We check if the word length is greater than 3 using > and get the length with length().
Fill all three blanks to create a map of uppercase words to their lengths if length is greater than 4.
String words[] = {"tree", "house", "car", "elephant"};
int lengths[4] = {0};
for (int i = 0; i < 4; i++) {
if (words[i].[1]() [2] 4) {
words[i].[3]();
lengths[i] = words[i].length();
}
}size() which is not valid for Arduino String.< instead of > in the condition.We get the word length with length(), compare with >, and convert to uppercase with toUpperCase().