Tracking counts from 3 different instances of a class in one place

I may have over complicated my first post. I am using a class to run a test, and in this case I'm using it 3 times. Each class keeps track of how many cycles have been run of this test, but I would like to retrieve the data from each class and write it neatly into a file on an SD card. I have a working version that doesn't use classes, but as this is my first time using them, I'm having trouble. It doesn't even necessarily have to involve the SD card, if I know how to get the data together in one place even if it's just to Serial.print(); then I'll be well on my way.


In your class, are you using



return value;

Should be pretty easy to serial print “value”.

Thank you!

I am using a class to run a test, and in this case I'm using it 3 times.

Just to help you with the right terms, you are creating 3 instances, or objects, of the same class.

I would suggest you add a new method to your class, called for example writeResults. This method can take a parameter which is a File object. The method can write the important data inside the test object to the File object.

Some part of your code, perhaps in loop() or wherever, must know about all your test objects. It can open the SD file and call the writeResults method of each object, passing the File object for the file. Then it can close the file again.

Something like:

void loop() {
  File resultsFile ="results.txt", FILE_WRITE);


The writeResults method would be something like:

void TestClass::writeResults(File f) {
  f.println(... );