+ pinMode(13, OUTPUT);
+ pinMode(piezoPin, OUTPUT);
+ digitalWrite(13, HIGH);
+
+ // calibrate during the first five seconds
+ while (millis() < 5000) {
+ sensorValue = analogRead(sensorPin);
+
+ // record the maximum sensor value
+ if (sensorValue > sensorMax) {
+ sensorMax = sensorValue;
+ }
+
+ // record the minimum sensor value
+ if (sensorValue < sensorMin) {
+ sensorMin = sensorValue;
+ }
+ }
+
+ // signal the end of the calibration period
+ digitalWrite(13, LOW);