PyRaspBeta

← All practice problems

Raspberry Pi practice problem · Motors & actuators

Note names

HardBudget $3Python · gpiozero

A passive buzzer on GPIO18 with a series resistor that keeps the pin under 16 mA (220 Ω). Play this tune once, written as note names:

SONG = "F#5 F#5 G5 A5 A5 G5 F#5 E5 D5 D5 E5 F#5 F#5 - E5 E5"
  • Work out each frequency from its name in equal temperament: A4 = 440 Hz, each semitone ×2^(1/12), octaves start at C (so C5 is 9 semitones below A5, which is 880 Hz). # raises a note by a semitone.
  • Every token lasts 0.25 s: a note sounds for 0.2 s then is silent for 0.05 s; - is a rest (silent for the whole 0.25 s).
  • Start the first note at 0.5 s, and stay silent after the tune.

The test checks the pitch (±1.5 %) in the middle of several notes, that there are exactly 15 separate notes, and silence during the rest and afterwards.

More in Motors & actuators