Shop OBEX P1 Docs P2 Docs Learn Events
Sonar ranging unit - piezo crystal — Parallax Forums

Sonar ranging unit - piezo crystal

CrystalionxCrystalionx Posts: 18
edited 2005-09-28 19:35 in BASIC Stamp
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

  • steve_bsteve_b Posts: 1,563
    edited 2005-09-27 19:23
    So what are you asking?! tongue.gif

    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."
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-09-27 19:35
    I am assuming you are aquiring a value for the sonar range, it is a relatively simple task to convert that value to a frequency. First use LOOKDOWN to split the possible return values into ranges, using the comparison op <= or >= depending on how you structure the list. Then use the index returned by LOOKDOWN in a LOOKUP which will return the corresponding frequency you want to output to the piezo. Refer to the Stamp User's Manual for how to use LOOKUP and LOOKDOWN.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-09-28 19:35
    I am sensing you may not understand my explanation, here is a code example to show what I'm talking about:

    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
     
     
     
    

    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
Sign In or Register to comment.