error: redefinition of void setup () and void loop ()

We are trying to input a music code into our arduino with a tetris game and we get an error because loop and setup are defined in both the game code and music code. The music code is not saved as a zip library so I have to include it using a separate tab instead of just including the library. I included the file for our code that we have.

I don't know if there's a way to redefine loop and setup so the code still works the same or if there's a way to compile it into one code in order to not have loop and setup defined twice.

Tetris_With_Music.ino (21.4 KB)

We are trying to input a music code into our arduino with a tetris game and we get an error because loop and setup are defined in both the game code and music code. The music code is not saved as a zip library so I have to include it using a separate tab instead of just including the library. I included the file for our code that we have.

I don't know if there's a way to redefine loop and setup so the code still works the same or if there's a way to compile it into one code in order to not have loop and setup defined twice.

Tetris_With_Music.ino (22 KB)

You can make it compile as so

void setup() {
  old1_setup();
  old2_setup();
}
void loop() {
  old1_loop();
  old2_loop();
}

You cannot have two definitions of a function of the same name

If you're combining sketches, you need to combine the contents of the setup and loop functions into one setup and one loop function for the combined sketch.

This means that both files will need to be modified, and it may be best to combine into one single file.

If i deleted the delay lines in the music code would it work then?

It is also teling me I am using 68 bytes too much of memory.

If i deleted the delay lines in the music code would it work then?
Almost certainly not. Those delays are probably there for a reason.

It is also teling me I am using 68 bytes too much of memory.
If it's RAM you are using too much of you can usually move string constants out of RAM and into FLASH.

where in the code that I have would I input old_setup1 and old_setup2?

how would I do that?

Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Threads merged.

  • Moderator