MOZZI Multiple triggers for multiple sounds
hi,
relatively new arduino's attempting create kind of lofi drum machine. i've managed trigger 1 sound using button struggling more that. want 4 switches control 4 different sounds, e.g kick, snare, hi hat, clap . believe it's if statements . heres code far 2 buttons, 2 sounds.. appreciated!
relatively new arduino's attempting create kind of lofi drum machine. i've managed trigger 1 sound using button struggling more that. want 4 switches control 4 different sounds, e.g kick, snare, hi hat, clap . believe it's if statements . heres code far 2 buttons, 2 sounds.. appreciated!
code: [select]
#include <mozziguts.h>
#include <sample.h> // sample template
#include <samples/drumkit/hat.h>
#include <samples/drumkit/snare.h>
const int button4 = 4; // number of pushbutton pin
const int button5 = 5; // number of 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 @ speed 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();
}
Arduino Forum > Using Arduino > Audio > MOZZI Multiple triggers for multiple sounds
arduino
Comments
Post a Comment