A fun uniting of digital (Arduino) and analog (human) output. Kitchen pots were placed upside-down to the right of the drum. An extra pair of drumsticks were marked as "Human Input "A" and "Human Input "B". A user-controlled potentiometer supplied analog voltage readings to the Arduino, which were then judged by IF statements in the code. The resulting data determined which of three drum rhythms to play (with a 4th IF statement for "off"). Each drum rhythm was just a series of 1's and 0's in an array. After the strikes, I would recommend a delay of about 20 miliseconds. Also, play with a delay at the end of the rhythm loop (depending on desired tempo.)
// A little example code for one rhythm
// "val" is the pot reading. My code has this value remapped from 0-4000.
val = analogRead(pot); // read the pot to determine current value
val = map(val, 0, 1023, 0, 4000); // you do not have to remap like I did,
// but if not, adjust code accordingly
//Note: when val<500, I have it sit in a WHILE statement until the value breaches
// that threshold. This is a static "off" position.
//////////////////////////////
//////////////////////////////
/// POT IS SET FOR BEAT 1
//////////////////////////////
//////////////////////////////
if (val>500 && val<=2400){ // potentiometer reading in this range???
tempo=120; // this is just a delay value, not tempo in the traditional sense
for (int i=0; i < 64; i++){ // 64 values in my rhythm array
if (drum1[i]==1){ // drum1 (stick 1) array value == 1, hit the stick
digitalWrite(drum1Pin, LOW); // NOTE: LOW for my setup. Yours may be different.
}
if (drum2[i]==1){ // drum2 (stick 2) array value == 1, hit the stick
digitalWrite(drum2Pin, LOW);
}
delay(20);
digitalWrite(drum1Pin, HIGH); // reset pins for next hit
digitalWrite(drum2Pin, HIGH);
delay(tempo);
val = analogRead(pot); // after any strikes, read pot again for next action
val = map(val, 167, 1023, 0, 4000);
if (val<=500 || val>2400){ // IF POT OUT OF RANGE, BREAK LOOP
// (resume main loop)
break;
}
}
}