0
0
Arduinoprogramming~10 mins

Timer interrupts with TimerOne library in Arduino - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize TimerOne with a 1-second interval.

Arduino
#include <TimerOne.h>

void setup() {
  TimerOne.[1](1000000); // 1 second interval
}

void loop() {
  // main code
}
Drag options to blanks, or click blank then click option'
Astart
Binitialize
CsetPeriod
Dbegin
Attempts:
3 left
💡 Hint
Common Mistakes
Using start() instead of setPeriod().
Using initialize() which is not a TimerOne function.
2fill in blank
medium

Complete the code to attach an interrupt service routine named blinkLED.

Arduino
void setup() {
  TimerOne.setPeriod(500000); // 0.5 second
  TimerOne.[1](blinkLED);
}

void blinkLED() {
  // toggle LED
}
Drag options to blanks, or click blank then click option'
AattachInterrupt
BonTimer
CsetInterrupt
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using start() which only starts the timer.
Using setInterrupt() which is not a TimerOne method.
3fill in blank
hard

Fix the error in the code to start the timer after setting the period and ISR.

Arduino
void setup() {
  TimerOne.setPeriod(2000000); // 2 seconds
  TimerOne.attachInterrupt(blinkLED);
  TimerOne.[1]();
}

void blinkLED() {
  // toggle LED
}
Drag options to blanks, or click blank then click option'
Astart
Bbegin
Cenable
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Using begin() which is not a TimerOne method.
Using enable() or run() which do not exist.
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.

Arduino
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]();
  }
}
Drag options to blanks, or click blank then click option'
A>
Blength
Csize
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of > in the if condition.
Using size() which is not a String method in Arduino.
5fill in blank
hard

Fill all three blanks to create a map of uppercase words to their lengths if length is greater than 4.

Arduino
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();
  }
}
Drag options to blanks, or click blank then click option'
Alength
B>
CtoUpperCase
Dsize
Attempts:
3 left
💡 Hint
Common Mistakes
Using size() which is not valid for Arduino String.
Using < instead of > in the condition.