Do I combine sketches from tutorials, or upload them separately?

Hi Community, this is my first project connecting an mpu6050 gyro to a Mega 2560. I've added the libraries for gyro and 12Cdev scanner, now I'm writing the sketch.
Following this tutorial...

It has two code sections, one for the gyro, and one for the scanner - should I copy/paste both sets of code (without duplicating the 'void' and 'loop' parts), into one long sketch, or should they be used separately, i.e. uploading two sketches to the Mega?

thanks for checking out this noob question.

You can only have one sketch loaded at a time so you will need to combine them.

Thanks very much for clarifying that :slight_smile:

One other question, can there be multiple instances of the void and loop?

No.

Topic moved to Programming Questions.

"void" is simply specifying what the function returns. Where void has the meaning of "return nothing"

void myFunction() {
}
int mySquare(int myNumber) {
  myResult = myNumber * myNumber;
  return myResult;
}

function named "mySquare" which returns a number of type int

use

int SQ;
int aNumber;

SQ = mySquare(aNumber);

"loop" is the name of the function

void setup

and

void loop()

are always required

Take a look into this tutorial:

Arduino Programming Course

It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.

best regards Stefan

Thank you, the tutorial is good explanation.

I can see the two sketches I have need to be run separately, one is for finding a port-address, the other is for running code communication to the ID'd port.

Tutorial on merging Arduino codes.

That's ideal, I know I'll be doing a lot of copy/pasting to merge scripts for this complex project.

I have to add in GPS, an A2D converter, and dual motor-controller board, all in same sketch.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.