mirror of
https://bitbucket.org/skobkin/arduino_guitar_repeater.git
synced 2024-11-22 04:16:02 +00:00
initial
This commit is contained in:
commit
3def7bd1c8
34
guitar.ino
Normal file
34
guitar.ino
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in a new issue