how to declare multiple similar objects ?

emmanuel63

Well-known member
Hello,

This is probably a stupid question, but I don't know how to declare multiple objects. There must be a way to do this, but I don't know how.
For instance, I have a MIDI controller with 24 pots. I use the ResponsiveAnalogRead library to smooth the noise. Then I make an array to handle my pots in my sketch. Here is the way I do it :

Code:
ResponsiveAnalogRead pot0(38, true);
ResponsiveAnalogRead pot1(38, true);
ResponsiveAnalogRead pot2(38, true);
ResponsiveAnalogRead pot3(38, true);
ResponsiveAnalogRead pot4(38, true);
ResponsiveAnalogRead pot5(38, true);
ResponsiveAnalogRead pot6(38, true);
ResponsiveAnalogRead pot7(38, true);
ResponsiveAnalogRead pot8(38, true);
ResponsiveAnalogRead pot9(38, true);
ResponsiveAnalogRead pot10(38, true);
ResponsiveAnalogRead pot11(38, true);
ResponsiveAnalogRead pot12(38, true);
ResponsiveAnalogRead pot13(38, true);
ResponsiveAnalogRead pot14(38, true);
ResponsiveAnalogRead pot15(38, true);

ResponsiveAnalogRead pot16(39, true);
ResponsiveAnalogRead pot17(39, true);
ResponsiveAnalogRead pot18(39, true);
ResponsiveAnalogRead pot19(39, true);
ResponsiveAnalogRead pot20(39, true);
ResponsiveAnalogRead pot21(39, true);
ResponsiveAnalogRead pot22(39, true);
ResponsiveAnalogRead pot23(39, true);
ResponsiveAnalogRead pot24(39, true);
ResponsiveAnalogRead pot25(39, true);
ResponsiveAnalogRead pot26(39, true);
ResponsiveAnalogRead pot27(39, true);
ResponsiveAnalogRead pot28(39, true);
ResponsiveAnalogRead pot29(39, true);
ResponsiveAnalogRead pot30(39, true);
ResponsiveAnalogRead pot31(39, true);

ResponsiveAnalogRead *pot[] = {&pot0, &pot1, &pot2, &pot3, &pot4, &pot5, &pot6, &pot7, &pot8, &pot9, &pot10, &pot11, &pot12, &pot13, &pot14, &pot15,
                               &pot16, &pot17, &pot18, &pot19, &pot20, &pot21, &pot22, &pot23, &pot24, &pot25, &pot26, &pot27, &pot28, &pot29, &pot30, &pot31
                              };

There must be another way to declare all my pots...

Thanks for your help
Emmanuel
 
For your example
Code:
ResponsiveAnalogRead *pot[32];
int i=0;
while (i<16)
      pot[i++] = new ResponsiveAnalogRead(38, true);

while (i<32)
      pot[i++] = new ResponsiveAnalogRead(39, true);
 
Thank you !!
I am not a wizard of C++ as you can see...

I have seen your enhanced audio design tool. I didn't try it yet, but it seems just amazing. I hope it will be the standard tool soon.
Respect !
 
here is a complete working 8 voice poly synth (the voice count can actually be anything up to 255)
it uses both USB and hw-serial MIDI
note. that it's using passthrough:
hw-serial MIDI -> USB
but not the other way around

it's in the simplest format,

but note that everything is structured into some (code & var) nodes
so it can look bigger than it's

and is a minified version of my PolySynth

Code:
https://raw.githubusercontent.com/manicken/manicken.github.io/master/examples/SimplePolySynth.json

it's set to generate a folder inside the exported zip

that way you only need to extract that folder
anywhere you want it

and then you open it as a ordinary sketch

I have verified it on my end, and it's working with a Pt8211 connected to the i2s port 2
note. that I have included the setup part for the SGTL5000 so it should just be compile and run.
 
Working !
Thank you.

Pt8211 was causing error when compiling, so I have deleted it and it compiles and plays.

I am now going to understand better how this tool work.
Emmanuel
 
Back
Top