Bird
0
0
Arduinoprogramming~10 mins

Playing melodies with tone() 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 play a tone on pin 8 at 440 Hz.

Arduino
tone(8, [1]);
Drag options to blanks, or click blank then click option'
A440
B8
C1000
Dtone
Attempts:
3 left
💡 Hint
Common Mistakes
Using the pin number as the frequency.
Using the function name as a parameter.
2fill in blank
medium

Complete the code to stop the tone playing on pin 8.

Arduino
noTone([1]);
Drag options to blanks, or click blank then click option'
A440
B1000
Ctone
D8
Attempts:
3 left
💡 Hint
Common Mistakes
Passing frequency instead of pin number.
Passing the function name.
3fill in blank
hard

Fix the error in the code to play a 500 Hz tone for 1000 milliseconds on pin 9.

Arduino
tone(9, [1], 1000);
Drag options to blanks, or click blank then click option'
Atone
B9
C500
D1000
Attempts:
3 left
💡 Hint
Common Mistakes
Using the pin number as frequency.
Using the duration as frequency.
4fill in blank
hard

Fill both blanks to create a dictionary of notes with their frequencies and play the note 'C' on pin 7.

Arduino
int notes[] = [1];
tone(7, notes[[2]]);
Drag options to blanks, or click blank then click option'
A262, 294, 330
B0
C1
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong indices for notes.
Not using correct frequencies.
5fill in blank
hard

Fill all three blanks to create a loop that plays notes from an array on pin 6 with 500 ms delay between notes.

Arduino
int melody[] = [1];
for (int i = 0; i < [2]; i++) {
  tone(6, melody[[3]]);
  delay(500);
}
Drag options to blanks, or click blank then click option'
A262, 294, 330, 349
B4
Ci
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong loop count.
Using fixed index instead of loop variable.