Timing Specifics

System Counter and Wait Until Blocks

The Visual Metronome is all about timing. Most of the code is self-explanatory, but the use of these blocks in the metronomeTime processor should be understood since they manage the timing. Here’s how they work:

  1. Two variables are created. The QuarterMinute variable is equal to the system clock frequency multiplied by 15 - which works out to be 15 seconds. The tSync variable is the current value of the system counter - some value between 0 and 4,294,967,295 which rolls over (the actual number doesn’t matter since we’re only interested in elapsed time). These variables are only assigned once.   
    Quarter minute block calculation from system counter

  2. The tempo is calculated in the repeat-forever loop. The HalfPeriod equal to QuarterMinute divided by (BPM beats per minute, dividied by two). Next, the tSync variable is calculated. It is set to tSync (the current value of the system counter, stored before the loop) plus the HalfPeriod. Knowing the half period is convenient for turning sound on and off, along with the lights.    
    Half period calculation

  3. The code running in this loop is less than half of the period (a beat). When the loop is done, the wait until block is encountered and causes the program to stop until the next calculated period has elapsed (tSync).
    The wait until block in the Visual Metronome BlocklyProp project.

 

Setting the Time Signature

The example code uses 4:4 (four beats per measure). To change this to 3:4 (triple time, as commonly used for the waltz and minuet) or 2:4 (duple, as used in polka or a march) you only need to change the loopCounter variable to the desired number of beats per measure.

And, change the case statement to reflect the number of beats per measure and the colors set on the NeoPixels:

Case statement block in the Visual Metronome project.

 

Effectiveness of the Visual Metronome

While I’m still struggling with keeping timing on the clarinet, it’s mostly a result of having stopped taking lessons though early tests show the Visual Metronome is a step in the right direction. I’m going to modify the beep to be a short “click” and use less intrusive colors as the next adjustment. Another change suggested by a Parallax engineer is to make the light tubes alternate between left and right, like a mechanical metronome swinging back and forth. 

When I put it in front of my son he seemed to know what to do right away on the piano, as shown below.

 

Additional Learn Resources