Sonar ranging unit - piezo crystal
Crystalionx
Posts: 18
I have set up the sonar ranger - it works great up to 354 centimeters. I have looking to now link up the ranger with a piezo so that it will beep at pre-determined distances. I hope that I can hybridize the program with if and statements relating to freq out but if such a program now exists I am of course interested.
Comments
Do feel free to post your project in the PROJECTS forum for others to idolize!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·
Steve
"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
This code takes the value returned by your sonar and splits it into 4 different ranges. The code assumes the range is between 0 and 255, you have to change these values to the actual values you are getting, and also change however many regions you want by including the top number of that range in the list of increasing order. LOOKDOWN will return the index of the·range the value is in, so if you get a value of 100, LOOKDOWN will return 1 since it is less than 128 (LOOKDOWNs index start with 0, so 1 is the second region), that index is then used to lookup the corresponding frequency for the range, in the example of 100 being returned by the sonar, the frequency 5000 is returned since it is at index 1. FREQOUT then plays a second long note of 5kHz on the pin you have the piezo connected to and that you have defined as the name Piezo in your program. Change the frequencies as you want them.
Is this a better explanation?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10