LED lights on Electronic Drum


First, you should simplify your code to work with just one drum, 'till you've got it working and debugged.

The biggest issue I see is the delay... You are only reading the inputs for one instant every 1/10th of a second. If you don't read at exactly the right time, you'll miss the hit.

One way to fix that is to make a "tight loop" (a loop without delays) and keep looping until a hit is detected. Then, you can exit the loop, trigger the LED, send-out a message to the serial monitor, and delay before re-starting the main loop. A [u]while() loop[/u] or a [u]do-while loop[/u] would be appropriate.

We also have no idea if the threshold is correct. Use the serial monitor to display your ADC (analog) readings.

int snareLedState = LOW; ...

...snareLedState = !snareLedState;

That might be a problem also. Since you want the state to be high or low, use a type boolean instead of a type int.



I won't attempt to give you the code because I can't test it, but the logic of a while() loop would be:

while(there's no no drum hit)
// Loop and do nothing.

When there is a drum hit (when whatever's in the parenthesis is false), the looping will stop and your program will continue below the loop.

In other words, you'll be stuck in a "do-nothing" loop (just checking for a drum hit) 'till you find a drum hit.

boolean snareLedState = false;

Yes. (Or you can use LOW instead of false.) A type boolean is high (high = 1 = true) or it's low (low = 0 = false).

Type int can hold any value between -32,768 and + 32,767, and that's not what you want.

The "!" symbol will invert/toggle the state of a boolean to the opposite state, but I'm not sure what happens with an integer value. (It might work, but there are really only two valid values/states you really want a one or a binary zero.)