PROSe Sample Code: Specifics this time

So my team is experiment with PROSe and its capabilities. We are getting a VEX speaker and want to play sounds. We also have an LCD screen and want it to display the battery level of the main battery. It also has to function (drive, etc.). Can someone give me some basic sample code that accomplishes these things (just two motor drive for functionality, one if you want, it’s just an example.) I don’t know a great deal about programming and hopefully my partner will have an account soon (he is the programmer in the group) and can contribute to the thread.

We are working on our example code, particularly for less often used aspects like the speaker. I took this example from the automated test bench for the VEX speaker which plays a short melody in autonomous mode if placed in auto.c:

void autonomous() {

Note that speakerPlayRtttl waits for the song to finish before continuing. If the song is to be played during driver control or autonomous while also performing other operations, start a new task and play the song inside it. PROS also can play multiple tracks to include harmony with a song; for details, see speakerPlayArray.

Taken from init.c in some old robot code of ours:

void initialize() {
    unsigned int voltage;
    // Change "uart1" to "uart2" if LCD is plugged into port marked "UART 2"
    lcdSetText(uart1, 1, "Purdue SIGBOTS");
    // Displays battery level properly as a psuedo-decimal
    voltage = powerLevelMain();
    lcdPrint(uart1, 2, "Batt: %d.%03d V", voltage / 1000, voltage % 1000);

Since powerLevelMain returns the voltage as millivolts (voltage * 1000), a reading of 7.2 V will return 7200. The division and modulus operators properly reformat the reading back into volts.

A basic example for tank drive is available in the PROS online documentation which takes the two vertical joystick axes and sends them directly to motor ports 2 and 9. The function belongs in opcontrol.c and is reproduced here:

void operatorControl() {
    while (1) {
        // Read joystick values
        int joystick1 = joystickGetAnalog(1, 3);
        int joystick2 = joystickGetAnalog(1, 4);
        // Optionally process joystick values
        // Send joystick outputs to motors
        motorSet(2, joystick1);
        motorSet(9, joystick2);
        // Joystick and motor values refreshed every 20 ms

Awesome!!! Thanks so much!!!

How might you put a song on the cortex to play?

@Jabibi @frydaddy07

What exactly are you asking for? I’m not sure I follow. MP3 and audio files aren’t supported by the PROS kernel since it’s somewhat beyond the scope of what a typical team needs. It might be possible to port an audio decoder to the Cortex. However, I’m somewhat hesitant that the program might be too large to fit on the Cortex, esp. combined with the actual audio file.

@edjubuh I know a lot more about this and rtttl format and stuff now. Thanks!

My apologies, I had forgotten that PROS documentation has been updated (we made the update, and it only recently went live due to winter break) with the old tutorial covering the VEX Speaker:

Hey, how to upload firmware to the microcontroller?
屏幕快照 2017-01-16 上午10.12.41.png

Tony, how do you have the Cortex connected to your computer? You may be able to find drivers for macOS that support USB A-A operation. Only the Programming Hardware Kit works out of the box.