View attachment 12249 I get random numbers with or without jumper0 196532 229464 2192
Thanks, I appreciate your help, I tried the first test connecting A21 to A0 and running your code The serial monitor just keeps printing 2 rows of 4 digit numbers, It makes no difference when I disconnect the jumper. fried?
@seayaker - ... If you click the "#" hashtag icon it adds HTML markers in the post to inset and format the code as shown in above posts to be more readable.
...
void MakeMidiNote() {
Serial.println("Midi Note to follow!");
// Add working test code here
}
const int thresholdMin = 12; // minimum reading, avoid "noise"
const int aftershockMillis = 60; // time of aftershocks & vibration
int state=0; // 0=idle, 1=looking for peak, 2=ignore aftershocks
int peak; // remember the highest reading
elapsedMillis msec; // timer to end states 1 and 2
void setup() {
Serial.begin(115200);
//pinMode(A0, INPUT_DISABLE);
while (!Serial && millis() < 4500) /* wait for serial monitor */ ;
Serial.println("Piezo Peak Capture");
}
void loop() {
int piezo = analogRead(A0);
if (state == 0) {
// IDLE state: if any reading is above a threshold, begin peak
if (piezo > thresholdMin) {
//Serial.println("begin state 1");
state = 1;
peak = piezo;
msec = 0;
[B][U] MakeMidiNote();[/U][/B] // When a value over thresholdMin is seen it will call the function to execute the NOTE code above
}
} else if (state == 1) {
// Peak Tracking state: for 10 ms, capture largest reading
if (piezo > peak) {
peak = piezo;
}
if (msec >= 10) {
Serial.print("peak = ");
Serial.println(peak);
//Serial.println("begin state 2");
state = 2;
msec = 0;
}
} else {
// Ignore Aftershock state: wait for things to be quiet again
if (piezo > thresholdMin) {
msec = 0; // keep resetting timer if above threshold
} else if (msec > 30) {
//Serial.println("begin state 0");
state = 0; // go back to idle after 30 ms below threshold
}
}
}
and still nothing
.....
I have to his connected a DAW that all keys should make a sound, I don't know how this is mapped but if its the same as the buttons sketch it should trigger something.
This 10K resistor gives the piezo a load to drive. The result is much lower noise at the analog pin. In this test I used 10K, but you can adjust this resistor for more or less sensitivity.
I changed the 470 resistor with a pot because Paul said I may have to experiment with it
so the number changes I put a pot in place of the 470 resistor with the center to gnd