Fun Projects for your LEGO MINDSTORMS NXT!

Home     Projects     Help     Contacts

Music Scale Player

Building Instructions

Programming Instructions

This first program uses color sensor events to play different notes in a major scale in the simplest possible way. Because there are only 7 unique colors, the scale can only have 7 different notes. Also, you will notice a few problems with how it works, which the more advanced program below tries to fix.

This more advanced program plays an 8-note major scale, with the top C (black) an octave higher than the bottom C (also black). It will switch to a minor scale if you hold down the right arrow button on the hub while playing.

In addition, this program uses various logic techniques to address several problems with the simpler program above, including:

  1. Blue and teal are easily confused by the sensor when the color is first coming into view, which can cause the "wrong" event to be sent. The improved program looks at changing color values in a loop to help get around this.
  2. Since similar colors can still be confused, the improved program uses a "heuristic" trick of assuming that the scale must be played in sequence (up or down) to help predict the correct note to play.
  3. The improved program also uses the note order heuristic to distinguish between high C and low C. High C must come after B in the scale. This heuristic is not perfect, and you can confuse it if you try.
  4. Stray "no color" readings are common when colors are changing, and very common with red in particular in this setup. The improved program filters these out.
  5. Instead of using "no color" to detect when the color stick has been removed, a timer is used, to hold the last note for 1/2 second, which also sounds nice.

Home     Projects     Help     Contacts


Copyright 2007-2021 by Dave Parker.  All rights reserved. 
All project designs, images, and programs are protected by copyright.  Please see the usage policy.