Hi,
i want to create a library to read an ic called MSGEQ7. I want the library do two things:
I can use it kinda like a return to get my preconfigured array to the read ones.
Or if i dont wanna use an extra array (for example if i only need one array for the whole programm) i just want to use an array which is in the class itself.
My code is working fine. I just want to ask if it is “good code” or if i can improve something.
.ino:
//Two ways of getting the input
//using a declared array before
myMSGEQ7.read(spectrumValueLeft, spectrumValueRight);
int input=spectrumValueRight[frequency];//<----------work here
//using the preconfigured array in the function
//myMSGEQ7.read();
//int input=myMSGEQ7.right[frequency];//<----------work here
.h:
public:
MSGEQ7(const int resetPin, const int strobePin, const int analogPinLeft, const int analogPinRight); //constructor
int left[7];//intern variable
int right[7];//intern variable
void read(); //use the intern variables MSGEQ7.right/left
void read(int l[], int r[]); //write external variables
.cpp:
void MSGEQ7::read(){ //use the variables MSGEQ7.right/left
read(left, right);
}
void MSGEQ7::read(int l[], int r[]){ //<--int &leftval
digitalWrite(_resetPin, HIGH); //resets the IC
digitalWrite(_resetPin, LOW);
for (int i = 0; i < 7; i++){ //63Hz, 160Hz, 400Hz, 1kHz, 2.5kHz, 6.25KHz, 16kHz
digitalWrite(_strobePin, HIGH); //Prepare for next value
digitalWrite(_strobePin, LOW); //Next value for the IC
delayMicroseconds(36); // to allow the output to settle
l[i] = analogRead(_analogPinLeft); //read left pin
r[i] = analogRead(_analogPinRight); //read right pin
}
}