notasium:
OK, I apologize. I was trying to just us the LED light as a test, but it seemed to add some confusion and perhaps over complicated things.
All I really want to do is send a signal to a WAV Trigger board when the Piezo sensor detects a signal.
The Piezo sensor part of this code is working fine. The WAV board is also getting a signal and triggering the sound. The problem is, it's triggering all the sounds on the board instead of one. I know the WAV board is setup correctly because when a switch is connected, instead of the Uno, it works perfectly. It chooses randomly between 3 different audio files to play. It plays one sound just once.
This is why I thought that using a LED light as a test would be better because if it would turn on and right back off that would act more like a switch.
The led is good but your eyes are too slow to see it flicker faster than 24x a second.
This sketch will show the raw reads at about 20 per second just to give ballpark data figures.
With those we have step one in converting the data into different midi sound triggers.
int piezoPin = A0; // the number of the input pin
int LED = 13; // the number of the output pin
int state = HIGH; // the current state of the output pin
int reading; // the current reading from the input pin
int previous = LOW; // the previous reading from the input pin
void setup()
{
Serial.begin( 250000 ); // as fast as it can be, change Serial Monitor to match
pinMode(piezoPin, INPUT);
pinMode(LED, OUTPUT);
}
void loop()
{
reading = analogRead(piezoPin);
Serial.println( reading);
if (reading > 1 && previous == 0) {
if (state == HIGH)
state = LOW;
else
state = HIGH;
}
digitalWrite(LED, state);
delay(50); // it will now show almost 20 reads a second
previous = reading;
}
What you've shown is that one hit makes the table vibrate for some period of time. To your or my senses it is a moment. To 16MHz Arduino it is a good while. If you want 1 hit makes 1 sound then the code will need to watch the whole event, record the highest value in a variable and/or with how many reads in the group above some low threshold to determine how hard the table was hit. A good look at the data will tell. For that you don't want to mess with the data.
Where you have the piezo connect to the pin, do you also have a pulldown to drain the wire? With my digital read-and-count method I did not since I used the reads to drain the wire, but I was reading that pin more than 100x in the time it would take to make a single analog read. 10 bit analog read takes 105 micros, a digital read takes less than 1 micro.
I give you these facts to try and shed light on what you are doing. The data will put numbers on that. You are not so far from different sounds for different hits as may seem.