Please how do you formulate this in C code for Arduino?
If I have this inside a loop:
and a function
then I'll hear my drum1 played. drum1 being an element from the Audio Library
I have 4 drums elements drum1, drum2, drum3, drum4, like in SimpleDrum.ino tutorial example.
The question is how can drum1 be dynamic. I mean replaced by a variable so it could be drum1, drum2, drum3 etc that I have for instance placed in an array, so I can call dynamically. I have to know so my code can look way simpler and not with plenty switch/break lines of code (when I use for something else with more elements in the array, which also not stirngs or numbers).
WRONG:
const char drum = "drum1";
const char drum = drum1;
OK:
AudioSynthSimpleDrum drum = drum1;
I have no error, but then
drum.noteOn();
will do nothing.
If I write
AudioSynthSimpleDrum myDrums[] = {drum1, drum2, drum3, drum4};
I got no error but then
myDrums[].noteOn();
will do nothing.
This also won't work:
I have an issue with declaring myDrums[] and currentDrum.
EDIT: adding code tags
If I have this inside a loop:
Code:
if(millis() == next) {
next = millis() + 1000;
playDrum ();
}
Code:
void playDrum () {
drum1.noteOn();
}
I have 4 drums elements drum1, drum2, drum3, drum4, like in SimpleDrum.ino tutorial example.
The question is how can drum1 be dynamic. I mean replaced by a variable so it could be drum1, drum2, drum3 etc that I have for instance placed in an array, so I can call dynamically. I have to know so my code can look way simpler and not with plenty switch/break lines of code (when I use for something else with more elements in the array, which also not stirngs or numbers).
WRONG:
const char drum = "drum1";
const char drum = drum1;
OK:
AudioSynthSimpleDrum drum = drum1;
I have no error, but then
drum.noteOn();
will do nothing.
If I write
AudioSynthSimpleDrum myDrums[] = {drum1, drum2, drum3, drum4};
I got no error but then
myDrums[].noteOn();
will do nothing.
This also won't work:
Code:
AudioSynthSimpleDrum myDrums[] = {drum1, drum2, drum3, drum4};
AudioSynthSimpleDrum theDrum = myDrums[0];
void playDrum () {
theDrum.noteOn();
}
EDIT: adding code tags
Last edited: