Sonar Ping
Domanik
Posts: 233
I'm playing with an ActivityBot, Ping and sound and came up with this code to beep on a speaker as an object is detected. The rate and freq. change as the object gets closer. Kids love it and they can grasp what the code is doing when they have feedback and can make their own changes.
Dom...
/* Sonar.c */ #include "simpletools.h" // Include simple tools #include "ping.h" int main() // Main function { while(1) // Repeat indefinitely { int inDist = ping(15); // Get cm distance from Ping))) int inchDist = inDist/148; print("Dist = %d inches\n", inchDist); // Display distance pause(100 + inDist/100); if ( inDist > 4000) pause(150); if ( inDist > 8000) pause(200); if ( inDist > 10000) pause(250); if ( inDist < 12200) freqout(26, 80, (12200 -inDist) / 15 + 300); else { pause(100); freqout(26, 40, 550); freqout(26, 250, 300); } } square_wave(26, 1, 3000); //save to play with later [INDENT]square_wave_stop(); [/INDENT] }
Dom...
Comments
This is a really great idea, one that I plan to use with my kids. Thanks for posting it.