X-Git-Url: http://git.piffa.net/web?a=blobdiff_plain;f=piezo%2Fpiezo_1_tonePitchFollower%2Fpiezo_1_tonePitchFollower_ino%2Fpiezo_1_tonePitchFollower_ino.ino;fp=piezo%2Fpiezo_1_tonePitchFollower%2Fpiezo_1_tonePitchFollower_ino%2Fpiezo_1_tonePitchFollower_ino.ino;h=0000000000000000000000000000000000000000;hb=83f214211b042e93bd52e944f6481afdcd66470e;hp=b5e9d24547dda93e8a255fa0678be36b6e5caf13;hpb=ae46f04b54f49297dc1e916c575cbdae70095611;p=sketchbook_andrea diff --git a/piezo/piezo_1_tonePitchFollower/piezo_1_tonePitchFollower_ino/piezo_1_tonePitchFollower_ino.ino b/piezo/piezo_1_tonePitchFollower/piezo_1_tonePitchFollower_ino/piezo_1_tonePitchFollower_ino.ino deleted file mode 100644 index b5e9d24..0000000 --- a/piezo/piezo_1_tonePitchFollower/piezo_1_tonePitchFollower_ino/piezo_1_tonePitchFollower_ino.ino +++ /dev/null @@ -1,64 +0,0 @@ -/* -Pitch following - -The input from a photo resistor dictates the pitch of a piezo. - - - */ - -// These constants won't change: -const int sensorPin = A0; // pin that the sensor is attached to -const int ledPin = 9; // pin that the LED is attached to -int thisPitch ; - -// calibration variables: -int sensorValue = 0; // the sensor value -int sensorMin = 1023; // minimum sensor value -int sensorMax = 0; // maximum sensor value - - -void setup() { - // turn on LED to signal the start of the calibration period: - pinMode(13, 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); -} - -void loop() { - // read the sensor: - sensorValue = analogRead(sensorPin); - - // apply the calibration to the sensor reading - thisPitch = map(sensorValue, sensorMin, sensorMax, 120, 1500); - // map the analog input range (in this case, min - max from the photoresistor) - // to the output pitch range (120 - 1500Hz) - // change the minimum and maximum input numbers below - // depending on the range your sensor's giving: - - // in case the sensor value is outside the range seen during calibration - thisPitch = constrain(sensorValue, 120, 1500); - - - - // play the pitch: - tone(ledPin, thisPitch, 10); // Tone is built in function - delay(1); // delay in between notes -} -