There are two ways to play a melody with the robot:
Using the coding blocks in Mind+.
Using the Serial Protocol in Mind+, Arduino IDE, Python, and the Petoi mobile app.
You can use this coding block to make one tone.
There are several ways to join multiple tones together to make a melody:
To better understand the format, you can continue reading the next section.
The melody starts with the letter 'b', indicating a buzzer command. (No quotation marks are needed in the final command).
Notes are represented by numbers, with 0 or -1 for silence. Use 1-35 for the best effect on a buzzer.
Durations are also numbers, indicating how many parts a whole second is divided into (e.g., 2 = 1/2 second). This plays a single middle C (C3 = 14) for 1/2 second with no delay:
The space between the starting 'b' and the first number can be omitted:
A note longer than 1 second can be represented by two notes:
A difference of 1 in note number represents a half-scale tone (semitone), while a difference of 2 represents a whole-scale tone. You can define any note as the base (e.g., middle C3 = 14). This sets the reference point for your melody. So D3 will be 16, E3 will be 18, F3 will be 19, G will be 21, A will be 23, B will be 25, and C4 will be 26. C4 - C3 = 12. That's the so-called 12-Tone Equal Temperament. You may write a map in the code for quick conversion.
You can define multiple note-duration pairs separated by spaces or commas. It's easier to read if you use spaces to separate the notes within a sentence and use commas to separate sentences.
For example:
The Serial Monitor uses ASCII encoding and only allows a short melody of around 200 bytes. b 14 4 takes six bytes to store.
Use brackets []
to define a list. The numbers should all be separated by ','. The above example becomes:
or
The Python version with the 'B' token uses a more efficient Binary encoding to allow a longer melody. On NyBoard, it allows around 450 bytes, i.e., 250 notes. On BiBoard, it allows around 2500 bytes, i.e. 1250 notes.
After playing the melody, you can add a number at the end to define an optional delay (in seconds).
Refer to the example to send it to the robot using Python.
Copy and paste the number part of the command, and separate each number with ',' as the example in section 1.
In this example, we'll use C3 (base tone 14). But you can choose any note within the 5-30 range.
Write down the sequence of notes you want to play, considering half- and whole-tone jumps. Use numbers based on your chosen base tone (14). Include silent notes (0) for pauses.
Decide how long each note should play. Use numbers to represent fractions of a second (e.g., 4 = 1/4 second).
Command with the 'b' token
B,14,4,14,4,21,4,21,4,23,4,23,4,21,2,0,4,19,4,19,4,18,4,18,4,16,4,16,4,14,2
or
You can also test the following examples:
Play around with tones and duration sequences to create your own melodies. For more complex pieces, there are online resources and software that can translate musical notation to this format. You may even write prompts to let AI generate a melody for you!
For example, using Gemini to give you a raw melody sequence to start with:
You may share your prompt, which works directly with our community, at www.petoi.camp.
Remember, this is just the beginning—have fun composing!