Created
February 18, 2019 02:49
-
-
Save blister/c488726e70d9205305fc4d39948c6a51 to your computer and use it in GitHub Desktop.
Theremin Ranging Turnoff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void loop() { | |
// put your main code here, to run repeatedly: | |
long dist = msToCm(ping()); | |
if ( dist < 100.00 ) { | |
toneCounter = 0; | |
// 1 == min distance in cm | |
// 100 == max distance in cm | |
// 1500 == max frequency | |
// 500 == min frequency | |
int pitch = map(dist, 1, 100, 1568, 784); | |
tone(buzzer, pitch); | |
} else { | |
toneCounter++; | |
if ( toneCounter == 100 ) { | |
toneCounter = 0; | |
noTone(buzzer); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment