Music on Gen 1 brain

Hi, I am interested in having my bot play music, I don’t have time to listen to all the music notes to play a song is there anyway I can do this fast?

1 Like

Hi, first of all, welcome to the forums!
Now, if your song already exist, there is a chance that if u search “song name easy piano notes” u can found the song with letter notes, if not try using this as reference.
If your song does not exist or you wanna make major changes, use the image above as well.
Also, rembember that gen 1 brains only supports 1 sound at the time.

(sorry if my english is bad btw)


Put all the notes in an array and loop over the array. Copy paste the instrumental notes into a string, delete the lyrics, use a space as the token seperator, play each note and delete each character from a token array on every space, and end the loop at the null terminator. For example:

char music[] = "G# A C# C";
char note[4] = { 0 };
int i = 0;
    if(music[i] == ' ')
        memset(note, 0, sizeof(note));
    } else
        note[strnlen(note, 3)] = music[i];

The music array can easily be edited with a macro on Vim or Nano.


Here is the code for it -

#pragma region VEXcode Generated Robot Configuration
// Make sure all required headers are included.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>

#include "vex.h"

using namespace vex;

// Brain should be defined by default
brain Brain;

#define waitUntil(condition)                                                   \
  do {                                                                         \
    wait(5, msec);                                                             \
  } while (!(condition))

#define repeat(iterations)                                                     \
  for (int iterator = 0; iterator < iterations; iterator++)

// Robot configuration code.
motor Motor10 = motor(PORT10, ratio18_1, false);

controller Controller1 = controller(primary);
motor leftMotorA = motor(PORT1, ratio18_1, false);
motor leftMotorB = motor(PORT3, ratio18_1, false);
motor leftMotorC = motor(PORT5, ratio18_1, false);

motor_group LeftDriveSmart = motor_group(leftMotorA, leftMotorB, leftMotorC);
motor rightMotorA = motor(PORT2, ratio18_1, true);
motor rightMotorB = motor(PORT4, ratio18_1, true);
motor rightMotorC = motor(PORT6, ratio18_1, true);
motor_group RightDriveSmart = motor_group(rightMotorA, rightMotorB, rightMotorC);
drivetrain Drivetrain = drivetrain(LeftDriveSmart, RightDriveSmart, 319.19, 295, 40, mm, 1);

digital_out Stuff = digital_out(Brain.ThreeWirePort.A);

// Helper to make playing sounds from the V5 in VEXcode easier and
// keeps the code cleaner by making it clear what is happening.
void playVexcodeSound(const char *soundName) {
  printf("VEXPlaySound:%s\n", soundName);
  wait(5, msec);

// define variable for remote controller enable/disable
bool RemoteControlCodeEnabled = true;
// define variables used for controlling motors based on controller inputs
bool Controller1XBButtonsControlMotorsStopped = true;

// define a task that will handle monitoring inputs from Controller1
int rc_auto_loop_function_Controller1() {
  // process the controller input every 20 milliseconds
  // update the motors based on the input values
  while(true) {
    if(RemoteControlCodeEnabled) {
      // check the ButtonX/ButtonB status to control Motor10
      if (Controller1.ButtonX.pressing()) {
        Controller1XBButtonsControlMotorsStopped = false;
      } else if (Controller1.ButtonB.pressing()) {
        Controller1XBButtonsControlMotorsStopped = false;
      } else if (!Controller1XBButtonsControlMotorsStopped) {
        // set the toggle so that we don't constantly tell the motor to stop when the buttons are released
        Controller1XBButtonsControlMotorsStopped = true;
    // wait before repeating the process
    wait(20, msec);
  return 0;

task rc_auto_loop_task_Controller1(rc_auto_loop_function_Controller1);

#pragma endregion VEXcode Generated Robot Configuration

/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       {author}                                                  */
/*    Created:      {date}                                                    */
/*    Description:  V5 project                                                */
/*                                                                            */

// Include the V5 Library
#include "vex.h"
// Allows for easier use of the VEX Library
using namespace vex;

int main() {

edit: code tags added by moderators. Please remember to use them. Posts with untagged code may get rejected in future.

I am doing Super Mario Bros Theme

I wanted to make a robot that can play music and trying to figure out how. I see that example that you had, and I was wondering if you could explain that code (since I am new to coding, I don’t know what each line is). Also, wondering if it could also be used for C++ or Python coding languages. Thanks.

It just seperates each token in the music array and sends it to a function that can play a note.