Problem with values between 2 classes in ARDUINO

Hi guys, I’m completely new with Arduino stuffs and my company assigned me a project with MPU6050 module.

I’ve started to do some libraries (class in Arduino) and I’m completely stucked 'cause I don’t mange to understand :
How is it possible to link 2 classes, so that one can send the variables to another?

The code is too long, but this example should be fine…I’ve 2 classes…Class1 and Class2.

File header:

#ifndef Class1_h
#define Class_h
# include ....bla bla

Class Class1 {
public:
Class1();
int function1();
int function2();
int function3();
int function4();

}

#endif

File .cpp

#include <Class1.h>
#include .... bla bla

int i=0;

Class1::Class1() {.....

}

int Class1::function1{

if (i==0){
    function2(); // provides 6 values
    state++;
    delay(10);
  }

if (i==1) {
    function3(); // this function uses the 6 values from function2 and provide other 6 values
    state++;
    delay(1000);
}
if (i==2) {
   function4(); // this function prints the 6 values provided by function3
    
  }

int Class1::function2() {
//provides 6 values
}

int Class1::function3() {
//this function uses the 6 values from function2 and provide other 6 values
}

int Class1::function4() {
// this function prints the 6 values provided by function3
}

Code Arduino:

#include <Class1.h>
#include <Class2.h>
#include ..... bla bla

Class1 class1;
Class2 class2;

void setup() {
  // put your setup code here, to run once:

class1.function1(); // till here I can see all the values in the serial monitor

Serial.print(1°_value); // FIRST PROBLEM: this easy command doesn't manage to access to any //values

void loop() {


class2.function(); // it doesn't work
class2.function(1°_value,2°_value,3°_value,4°_value,5°_value,6°_value); // it doesn't work

}

Class2, and the function inside it, should use the values provided by the function1 in Class1.
But when I try to use, the compiler tells me that the variables are not assigned.
Practically, I don’t know how to allow the variables to be usable/visible between 2 classes or even more :slight_smile:

Could you tell me the way to solve this problem?
Every tip is very welcome.
Thank you so much .
Marco

You didn't tell us anything about Class2. I hope it isn't identical to Class1!

Please, post all the code or COMPILABLE minimal sketch that reproduces your problem.

yes, you right… sorry :slight_smile:

Class2 has just one function.
This function works with the 6 values provided by function1 in Class1.

The structure is almost the same but function in class2 doesn’t have any if cicle…

file .h

ifndef Class2_h
#define Class2_h
# include ....bla bla

Class Class2 {
public:
Class2();
int function();

}

#endif

File .cpp

#include <Class2.h>
#include .... bla bla

int i=0;

Class2::Class2() {.....

}

int Class2::function(){

// I need here the 6 values provided by function1 in Class1 to continue my calculus

}

OO is an option in C++, not a requirement. Do you really need classes?

If so, why do you need two classes? Why not have all your methods in one?

This is all very hypothetical without actual code.

#ifndef Class1_h
#define Class_h

If a value is not defined, define some other value. That is NOT how include guards work.

Class is a stupid name for a class.