Hello. Help me convert code to C++

Hello. I wanted you to help me converting my code to C++ because somethings i can not understand.

here is the code from this project that im trying to make. DIY sample-player w/Adafruit Trellis and Soundboard - YouTube

#include <Wire.h>
#include "Adafruit_Trellis.h"
#include <SoftwareSerial.h>
#include "Adafruit_Soundboard.h"

/************ sound board setup ***********/
// Choose any two pins that can be used with SoftwareSerial to RX & TX
#define SFX_TX 5
#define SFX_RX 6
// Connect to the RST pin on the Sound Board
#define SFX_RST 4

#define SFX_ACT 7 // the 'ACT'ivity LED, to tell us if we're still playing

// You can also monitor the ACT pin for when audio is playing!
// we'll be using software serial
SoftwareSerial ss = SoftwareSerial(SFX_TX, SFX_RX);
// pass the software serial to Adafruit_soundboard, the second
// argument is the debug port (not used really) and the third
// arg is the reset pin
Adafruit_Soundboard sfx = Adafruit_Soundboard(&ss, NULL, SFX_RST);

/************ Trellis setup ***********/

Adafruit_Trellis matrix0 = Adafruit_Trellis();
Adafruit_TrellisSet trellis = Adafruit_TrellisSet(&matrix0);

// set to however many you're working with here, up to 8
#define NUMTRELLIS 1
#define numKeys (NUMTRELLIS * 16)

// Connect Trellis Vin to 5V and Ground to ground.
// Connect the INT wire to pin #A2 (can change later!)
#define INTPIN 2
// Connect I2C SDA pin to your Arduino SDA line
// Connect I2C SCL pin to your Arduino SCL line

char PadToTrack[numKeys][12] = {"DOIT WAV",
"MAKEIT WAV",
"MAKESENSWAV",
"HARDER WAV",
"BETTER WAV",
"FASTER WAV",
"STRONGERWAV",
"WORKIT WAV",
"EVER WAV",
"AFTER WAV",
};

/************ main setup ***********/

void setup() {
Serial.begin(115200);
Serial.println("Trellis Demo");

// INT pin requires a pullup
pinMode(INTPIN, INPUT);
digitalWrite(INTPIN, HIGH);
// ACT LED
pinMode(SFX_ACT, INPUT);
digitalWrite(SFX_ACT, HIGH); //pullup

// begin() with the addresses of each panel in order
trellis.begin(0x70); // only one

// softwareserial at 9600 baud
ss.begin(9600);

if (!sfx.reset()) {
Serial.println("SFX not found");
while (1);
}
Serial.println("SFX board found");

uint8_t files = sfx.listFiles();

Serial.println("File Listing");
Serial.println("========================");
Serial.println();
Serial.print("Found "); Serial.print(files); Serial.println(" Files");
for (uint8_t f=0; f<files; f++) {
Serial.print(f);
Serial.print("\tname: "); Serial.print(sfx.fileName(f));
Serial.print("\tsize: "); Serial.println(sfx.fileSize(f));
}
Serial.println("========================");

trellis.clear();
trellis.writeDisplay();
}

int currentPlaying = -1;

void loop() {
//delay(30); // 30ms delay is required, dont remove me!

if (digitalRead(SFX_ACT) && (currentPlaying != -1)) {
// not playing anything according to ACT lite
trellis.clear();
trellis.writeDisplay();
currentPlaying = -1;
}
// If a button was just pressed or released...
if (! digitalRead(INTPIN)) {

trellis.readSwitches();
// go through every button
for (uint8_t i=0; i<numKeys; i++) {
// if it was pressed, turn it on
if (trellis.isKeyPressed(i) && (i != currentPlaying)) {
Serial.print("v"); Serial.println(i);

trellis.clear();

if (! digitalRead(SFX_ACT)) {
Serial.println("stop..."); // check ACT lite first?
if (! sfx.stop() ) {
Serial.println("Failed to stop");
}
}

// play!
char * filename = PadToTrack*;*

  • int ret = sfx.playTrack(filename);*

  • Serial.print("Playing "); Serial.println(filename);*

  • if (! ret) {*

  • Serial.println("Failed to play track?");*

  • } else {*

  • trellis.setLED(i);*

  • }*

  • trellis.writeDisplay();*

/* for my debugging

  • int ms = 0;*
  • while (digitalRead(SFX_ACT)) {*
  • delay(1);*
  • ms++;*
  • }*
  • Serial.println(ms);*
    */
  • delay(25); // give it a chance to start playing*
  • currentPlaying = i;*
  • break;*
  • }*
  • }*
  • }*
    }

What are you trying to accomplish? What is the problem you are having? This code looks like it should do something and I'm pretty sure it could also be compiled with a cpp compiler.

if you watch the video you will understand what im trying to do.
This code works if i put it through arduino IDE
but my teacher also wants me to "translate" it to C++

It is C++. There's just a kind of shell put on that leaves you filling out setup and loop that you can can rid of and still program the AVR. Just how, someone or some page somewhere else can tell you.

// put all the includes, defines, declares, etc outside of setup() and loop() here

void main()
{
// put the contents of setup() here

while ( 1 )
{
// put the contents of loop() here
}
}

My IDE wants to see setup( ) and loop( ):

/*
all the #includes, #defines, etc
 */

int main( ) {
    setup( );
    loop( );
}   

void setup( ) {
    // same setup
    ;
}

void loop( ) {
    // same loop
    ;
}

/*
same functions
 */

GoForSmoke is right. This is C++. You can nit-pick some things but...

Did he make any requirements about the library files used or another compiler?

but my teacher also wants me to "translate" it to C++

In other words, your teacher will not allow you to use any of the following libraries ?

 #include <Wire.h>
#include "Adafruit_Trellis.h"
#include <SoftwareSerial.h>
#include "Adafruit_Soundboard.h"

Maybe the instructor only knows standard C++ or wants to port the software.

I read that Eclipse is a good alternative IDE.
http://avr-eclipse.sourceforge.net/wiki/index.php/The_AVR_Eclipse_Plugin

This is a SOP for the professors
The way it works is they give their students working arduino code that includes libraries to demonstrate the assignment objective and then they they say " Do now you see what the program needs to do. Now do it WITHOUT the included Libraries ( I think they are allowed to write their own but are not allowed to use the available libraries).

I don't think that the professor wants the students to re-invent all the library code - ask!

Instead I suspect that the professor wants files that load in any C++ IDE. For that purpose I'd add a MyThesis.cpp module with mySetup() and myLoop() functions, containing the code from setup() and loop(), and replace the sketch by

#include "MyThesis"
void setup() { mySetup(); }
void loop()   { myLoop(); }

Eventually also a dummy Main.cpp module:

void ::Main() //is this correct C++ syntax?
{
  mySetup();
  while (1)
    myLoop();
}

No, he allows me to use anything i want, any library i want etc.

No, he allows me to use anything i want, any library i want etc.

So your assignment is to take a working C++ program and convert it into another C++ program that does the same thing?

jremington:
So your assignment is to take a working C++ program and convert it into another C++ program that does the same thing?

My assignment is to take this code make the changes needed and load it from CODE VISION to AVR DUDESS.

Delta_G:
Why didn't you say so in the beginning so you didn't lose so much time while we guessed at the nature of the assignment?

Yeah sorry im was a bit busy and confused but my teacher explained me what he wanted to do so.
can you help me with this?

Try posting on a Code Vision Forum. (although they probably don't do homework either)