This commit is contained in:
Alexey Skobkin 2013-07-28 07:43:43 +04:00
commit 3def7bd1c8

34
guitar.ino Normal file
View file

@ -0,0 +1,34 @@
int edge = 15;
const long d = 5;
int analogInPin = A0;
const int audioOutPin = 12;
void setup() {
Serial.begin(115200);
}
void loop() {
int freq = measureFrequency();
if (freq != 0)
tone(audioOutPin, freq);
else
noTone(audioOutPin);
Serial.println(freq);
}
int measureFrequency() {
long t = millis();
int n = 0;
boolean o = analogRead(analogInPin) <= edge;
while(millis() - t <= d)
if ((analogRead(analogInPin) <= edge) != o) {
o = !o;
n++;
}
return n * 1000 / d;
}