Hi,
relatively new to Arduino's but am attempting to create some kind of LoFi drum machine. I've managed to trigger one sound using a button but am struggling to get more than that. I basically want 4 switches to control 4 different sounds, e.g kick, snare, hi hat, clap . I believe it's to do with the If statements . Heres my code so far for 2 buttons, 2 sounds.. any help would be much appreciated!
#include <MozziGuts.h>
#include <Sample.h> // Sample template
#include <samples/drumkit/hat.h>
#include <samples/drumkit/snare.h>
const int button4 = 4; // the number of the pushbutton pin
const int button5 = 5; // the number of the pushbutton pin
boolean triggered = false;
// use: Sample <table_size, update_rate> SampleName (wavetable)
Sample <hat_table_NUM_CELLS, AUDIO_RATE> aHat(hat_table_DATA);
Sample <snare_table_NUM_CELLS, AUDIO_RATE> aSnare(snare_table_DATA);
void setup(){
startMozzi(CONTROL_RATE);
aHat.setFreq((float) hat_table_SAMPLERATE / (float) hat_table_NUM_CELLS);
aSnare.setFreq((float) snare_table_SAMPLERATE / (float) snare_table_NUM_CELLS); // play at the speed it was recorded
}
void updateControl(){
if(digitalRead(button4)==LOW){
if (!triggered){
aHat.start();
triggered = true;
}
}else{
triggered = false;
}
if(digitalRead(button5)==LOW){
if (!triggered){
aSnare.start();
triggered = true;
}
}else{
triggered = false;
}
}
int updateAudio(){
return (int) aHat.next();
}
void loop(){
audioHook();
}