Beeping Sonar
Crystalionx
Posts: 18
I have set up the sonar ranging unit, and now I want it to emit a beep at particular distances, through a piezo or other analog unit.· I am going to try to cut and paste one of the audio programs with if.then statement linked to certain distances.· I have no idea if this will work.· Is there an already existing program to accomplish this - if not, any suggestions?
Post Edited By Moderator (Jon Williams (Parallax)) : 9/28/2005 5:17:22 PM GMT
Post Edited By Moderator (Jon Williams (Parallax)) : 9/28/2005 5:17:22 PM GMT
Comments
And do be sure to add an appropriate subject heading to your new threads (I fixed this one).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
From your posts, I gather your sonar code is working, what are the values associated with 350, 175, 85 and 40 cm?
Have you tested the functioning of the piezo seperately? IE hooking it up and sending it various FREQOUT commands (straight FREQOUT commands, none of the sonar code or conditional statements)? If so does it work as expected?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 10/4/2005 5:56:47 PM GMT
Next time you are at the lab, can you place a debug statement in to see what values are being returned by the Lookdown·and Lookup command? Also posting the portion of code relating to this would be helpful (maybe a syntax error is present, or maybe I wrote the code down wrong, I can do a testing of the code section in question, though it may take me a little bit to get it setup)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 10/4/2005 9:20:10 PM GMT
This is the code I'm using:
'PingCentimeters.BS2.
' {$STAMP BS2}
' {$PBASIC 2.5}
time VAR Word
DO
PULSOUT 15, 5
PULSIN 15, 1, time
DEBUG HOME, "time = ", DEC5 time
time = time ** 2251
DEBUG CR, "Distance = ", DEC4 time, " cm"
PAUSE 100
LOOP
Range VAR Word
Freq VAR Word
'Get the sonar value and place in Range
LOOKDOWN Range, <[noparse][[/noparse]64, 128, 192, 255], Freq
LOOKUP Freq, [noparse][[/noparse]10000, 5000, 1000, 500], Freq
FREQOUT Piezo, 1000, Freq
When I ruin this I get an error message asking for values for freq. I can send you the error messages later.
I believe I grasp the index concept and I have used different values - I never get past RUN in any case.
That can't be the program, or at least it's not the whole program. The program you provided never asks for any input, and it also goes into an infinite loop, unless I'm missing something. The DO ... LOOP with no exit strategy is causing that latter problem.
Lastly, the following code is never being executed, if that is indeed a complete program:
LOOKDOWN Range, <[noparse][[/noparse]64, 128, 192, 255], Freq
LOOKUP Freq, [noparse][[/noparse]10000, 5000, 1000, 500], Freq
FREQOUT Piezo, 1000, Freq
Are you sure these programs you're writing are actually getting downloaded to the Stamp? Is there more to this program that you haven't provided?
Regards,
Bruce Bates
Post Edited (Bruce Bates) : 10/4/2005 11:36:58 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
350cm, 175cm, 85 cm, and 40cm
This will hopefully work as expected; instead of the exact value, a range is given to give a little more "play" in what is considered a valid distance to trigger the sound, I chose a range of 7 cm for each value, change this as you wish for it to be a tighter or looser range. I have set the Piezo on pin 2, change this to what pin you actually used. The tone will played for a half second, change this value to whatever you want. I chose 4kHz, 2kHz, 1kHz and 500 Hz for the frequencies, change the spread (value BFreq is divided by) and·the base frequency (BFreq) to whatever you want.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10