1. Purpose of the Case

Program the CoCube robot to achieve music programming.

2. Materials Used

CoCube Robot × 1 Personal Computer or Tablet

3. Software Platform

MicroBlocks-CoCube

4. Start Programming

The CoCube robot is equipped with a buzzer, which can be programmed to produce sounds of different pitches, adjust the duration of the tones, and control intervals to compose and play music:

  1. Connect Device: Connect the MicroBlocks IDE to the CoCube robot via a wired or wireless connection.

  2. Find Blocks: In the "Tone" block library, locate the "play frequency (261) for (500) ms" block and drag it into the workspace.

  3. Run Program: Left-click the block. When a green halo appears around the block, it indicates that the program has been successfully executed, and you will hear the CoCube robot's buzzer sound for 0.5 seconds before stopping.

  4. Adjust Pitch: Modify the pitch number and duration to produce sounds of different pitches.

  5. Compose Music: Here’s a set of middle-note frequencies: Do (523), Re (587), Mi (659), Fa (698), So (784), La (880), Xi (988). You can also look up the corresponding notes and frequencies online. Drag multiple blocks and modify the frequency and duration of each block to compose music.

  6. Stop Tone: To stop the buzzer from sounding, use the "stop tone" block. Simply click the "stop tone" block in the block area or drag it into the workspace and click it, and CoCube will immediately stop playing the sound.

5. Advanced Features

Looking up note-to-frequency mappings can be tedious. Is there a simpler way? MicroBlocks provides two convenient methods.

5.1 Notes

In music, notes like c, d, e, f, g, a, b represent Do-Re-Mi-Fa-So-La-Ti. A sharp (♯) raises the pitch by a semitone, and octaves (0, 1, 2…) indicate low, medium, high pitches, etc.

Try composing "Two Tigers". To make it easier to adjust the tempo of the music, we create a global variable beat and place it in each "play tone" block.

5.2 MIDI

In MIDI keyboards, MIDI Note Numbers correspond to musical pitches, mainly used for digital music production and communication between instruments.

For example, 60 represents middle C on the piano, 61 represents C#, 62 represents D, etc.

Try creating a sound effect:

6. Challenge

Use CoCube to try playing "Twinkle, Twinkle, Little Star."

Reference Example Program:

MicroBlocks——CoCube Case 04 - Music Programming

CC-BY-SA

© by CoCube 2024-2025.

This work is licensed under a CC-BY-SA 4.0 license.