MARY HAD A LITTLE LAMB

Below is an example of how you can play a musical tune using the RaspberrySTEM:


The code above is pretty simple -- we create a list of notes, and then we use a for loop to loop through them, play each in turn.  

Now, the one big issue with this code is that each note is of a fixed duration.  But, in most songs, you have notes of varying length (some longer and some shorter).  We can modify this code so that we can specify the length of each note independently.  We do that by creating a second list that contains the note durations, and in our for loop, we use both the note and the duration in our play() function.

Here is what the code would look like:


prev| next