Skip to content

Instantly share code, notes, and snippets.

@blister
Created February 18, 2019 02:49
Show Gist options
  • Save blister/c488726e70d9205305fc4d39948c6a51 to your computer and use it in GitHub Desktop.
Save blister/c488726e70d9205305fc4d39948c6a51 to your computer and use it in GitHub Desktop.
Theremin Ranging Turnoff
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