EV3COMPOS3R – a project to compose your own tunes

VERSION II is now published. The article here is instructive to read, but you are are better downloading the project files for version II from  a later post or
from EV3COMPOS3R II DOWNLOAD LINKS page

EV3COMPOS3R is a major project for Lego EV3. I have designed two versions, one of which can be built with the Retail 31313 set, and the other with a combination of the Education Core Set 45544 together with the Education Expansion Set 45560. In each case a project file is available containing full constructional details and the programs required.

EV3CPMPOS3R version for the Retail 31313 set

EV3COMPOS3R version for the Retail 31313 set

EV3COMPOS3R version for the Education 456544 and 45560 sets combined

EV3COMPOS3R version for the Education 45544 and 45560 sets combined

The project uses a total of 10 input devices! The position sensors on two motors are used to adjust the pitch and duration of the notes which will make up the tune, a push button is used to record the selected notes, an Infra-Red or Ultrasonic Sensor is used to select a menu for choosing the program options, the five buttons at the centre of the EV3 brick are used for multiple functions to choose the operations required, and a colour sensor (or a second push button sensor) is used to “nudge” the motor selecting the note pitch for fine adjustment.

The model consists of a framework to support the two motors and the sensors, and the output of the model is a tune which is stored in memory, and which can be fed to the sound chip on the EV3 brick. Facilities are also built in to allow up to 10 tunes to be saved to data files stored on the EV3 brick, which can also be uploaded to a PC if required.
One rotation of the left hand pitch motor controls the selection of the note pitch over a range of 3 octaves from C4 through C#4, D4, D#4…… up to C7, giving a total of 37 discrete notes.
One rotation of the right hand duration motor controls the selection of 16 different note durations ranging from 1 (semi-quaver), 2 (quaver), 3 (dotted quaver), 4 (crotchet) …. up to 16 (breve). Note durations that don’t have a simple musical name are signified by the duration in brackets, thus (5), (9), (10), (11), (13) and (15).

Because Lego has no error checking available if you try and read from a non-existent data file on the brick, a second program called initfiles is supplied the purpose of which is to write 10 empty data files to the brick before the main program called 002 is used.

Rests can be incorporated into a tune by selecting a note duration and holding down the DOWN button on the EV3 Brick while the note record push button is depressed.

Functions to delete the last recorded note, to clear the whole tune currently in memory, to Save or Load a tune to or from one of the 10 data files on the disk and to Playback the tune currently in memory are chosen from a menu which is selected by shading the Infra-Red or Ultrasonic-Sensor depending on the version being used. Two sub-menus allow for the selection of the file number to be used (1-10) and the selection of one of four preset playback tempo. To aid file selection, the tune length currently stored in each location is displayed when a file is selected.

The “nudge” facility previously referred to was added to make it easier to accurately select a note pitch, as the motor is a little “lumpy” to turn, and it is not always easy to select the correct position. On the 31313 version a red flap is rotated in front of the colour sensor, where it is detected, and the motor is switched on to rotate a small number of degrees. The same facility is added to the 45544 version using a push button to initiate the movement. If you rotate the motor manually to just below the pitch you require, you can then easily “nudge” the motor to the right position.

The program is quite complex. It employs 24 MyBlocks together with the two programs 002 and initfiles already referred to. The main program consists of five parts.
First an initialisation section bkInitialise displays some welcome screens, calibrates the two motor positions, and sets up one or two arrays and variables used by the program. Then four parallel processes are started, each consisting of an endless loop.

The first bkMPLoop (motor position loop) programs the two motors to produce integer numbers from 0 to 36 and from 1 to 16 to act as indexes for the pitch and duration values as they are rotated through just less than one revolution. Lookup arrays convert the pitch index values into the names of the notes and the frequencies of the notes which can in turn be displayed on the screen and fed to the speaker module. A lookup array is likewise used to display the duration names on the screen, and a divisor variable is used to adjust the tempo and produce the actual duration times fed to the speaker module.

The second process bkRecordLoop is used to record the selected pitch and duration index values each time the record button is pushed and store them in the successive elements of two arrays called tunenote and duration.

The third process bkBtnSkipLoop is the most complex, and deals with the various menu options for note deletion, loading and saving tunes to data files, clearing the current tune in memory and playing back the tune in memory. The heart of this section is a five way switch.

Further complexity is added to the first three parallel section by a variety of variable flags, which allow them to interact. Thus selecting a new note can exit the menu section (although this is inhibited whilst a tune is being played), and note recording is inhibited whilst a menu function is active. Also a flag allows the Infra-Red or Ultrasonic-Sensor to interrupt playback if you don’t want to listen to a tune in its entirety.

The fifth parallel process nudgemotorA contains the code to rotate the note pitch motor in small increments each time the relevant sensor is activated.

The program runs until it is stopped by pushing the stop button on the EV3 brick.

A short video of the project is here, and you can listen to one of the pieces on this link.

Better version of the video on youtube here

Downloads:
The retail version 31313 project file
The education version 45544 plus 45560 project file
A zip file of 10 tunes which you can download to the project folder on the EV3 brick

I hope you enjoy using this project. I welcome feed back comments!

 

Advertisements

4 thoughts on “EV3COMPOS3R – a project to compose your own tunes

    1. rbn2013 Post author

      They are contained in the project files. Download, unzip and load into your ev3 brick. You will see programs, and build instructions there.

      Reply
  1. Piotrek

    Witam, zaczynam małymi kroczkami programować swoje roboty. Zabawa jest świetna. Czy mogę liczyć na pomoc kiedy napotkam trudności?

    Reply
    1. rbn2013 Post author

      Cieszę się, że Ci się podoba roboty programowania. Jeśli masz problemy mogę tgry pomóc. (tłumaczenie przez Google)

      Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s