Shop OBEX P1 Docs P2 Docs Learn Events
Turning a number into "beeps" — Parallax Forums

Turning a number into "beeps"

ghost13ghost13 Posts: 133
edited 2007-06-07 15:36 in BASIC Stamp
I'm building an altimeter (for a rocket), and my current system of using an LCD to display the ADCout takes up too much power. Instead, I simply want to use a beeper to report the number. For example, 4392 would be:
beep-beep-beep-beep-long beep--beep-beep-beep-long beep--beep-beep-beep-beep-beep-beep-beep-beep-beep-long beep-beep-beep-
10 is represented by 10 normal beeps.

Is there a quick and simple algorithm to do this (I'm using the BS1)? Thanks!

EDIT: I figured most of it out, but I still have this question:
If you divide, say 3024, by 1000 (3024/1000), is the answer 3 or 3.024?
However, I'm simply using this as something to count up to in a loop, so does it even matter?

Thanks!

Post Edited (ghost13) : 6/7/2007 12:41:13 AM GMT

Comments

  • Kevin WoodKevin Wood Posts: 1,266
    edited 2007-06-07 01:17
    Have you considered using Morse code? Here is more info: en.wikipedia.org/wiki/Morse_code

    If you search search.parallax.com, you'll find more on the subject.
  • marlord0marlord0 Posts: 8
    edited 2007-06-07 01:40
    there is a command called DIG that tells you the digit of a number(like first, second, third digit) you maybe able to use that

    but I don't know if it is for BS1 though
  • ZootZoot Posts: 2,227
    edited 2007-06-07 02:03
    Somebody said...
    If you divide, say 3024, by 1000 (3024/1000), is the answer 3 or 3.024?

    The answer would be 3. The Stamp is integer math only. Check the Basic Stamp manual for info about the ** and */ operators which will let you do "fractions".

    If you want beeps as you describe, easiest way would probably be to extract your numerical values first, e.g.

    num VAR Nib
    myNumber VAR Word
    i VAR Nib
    ioByte VAR Byte
    
    FOR num = 4 TO 0                   ' loop through digits (5 digits with 10k first)
       ioByte = myNumber DIG num   'get the digit "value"
       FOR i = 1 TO ioByte                            'one "beep" per count
          FREQOUT pin, 25, ioByte*100+2000  'and  "beeps" for each "digit" are slightly different
          PAUSE 25
       NEXT
       PAUSE 250
    NEXT
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    Post Edited (Zoot) : 6/7/2007 2:11:56 AM GMT
  • ZootZoot Posts: 2,227
    edited 2007-06-07 02:09
    Whoops, just caught that you are on a BS1 which doesn't have the DIG function.

    myNumber VAR Word
    i VAR Nib
    ioByte VAR Byte
    
       ioByte = myNumber/10000   'get 10000s
       GOSUB Play_Number
       ioByte = myNumber//10000/1000   'get 1000s
       GOSUB Play_Number
       ioByte = myNumber//1000/100   'get 100s
       GOSUB Play_Number
       ioByte = myNumber//100/10   'get 10s
       GOSUB Play_Number
       ioByte = myNumber//10   'get 1s
       GOSUB Play_Number
    
    END
    
    'subroutine
    Play_Number:
       FOR i = 1 TO ioByte                            'one "beep" per count
          FREQOUT pin, 25, ioByte*100+2000  'and  "beeps" for each "digit" are slightly different
          PAUSE 25
       NEXT
       PAUSE 250
       RETURN
    
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • metron9metron9 Posts: 1,100
    edited 2007-06-07 05:04
    Another option might be to use a string of LEDS and use a similar algorithm you are for beeps but instead blink the leds.

    4321 would blink all leds on and off to signal the start then the 4th, third, second and 1st. I understand the rocket is probably in the sunlight but i think LEDs should be bright enough. I think trying to count all those beeps might get a bit tedious and I think LEDS would also be lower power as well overall.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • ghost13ghost13 Posts: 133
    edited 2007-06-07 05:32
    Thanks for your help. I'm going to use this code (thanks!):
    
    myNumber VAR Word
    i VAR Nib
    ioByte VAR Byte
    
       ioByte = myNumber/10000   'get 10000s
       GOSUB Play_Number
       ioByte = myNumber//10000/1000   'get 1000s
       GOSUB Play_Number
       ioByte = myNumber//1000/100   'get 100s
       GOSUB Play_Number
       ioByte = myNumber//100/10   'get 10s
       GOSUB Play_Number
       ioByte = myNumber//10   'get 1s
       GOSUB Play_Number
    
    END
    
    'subroutine
    Play_Number:
       FOR i = 1 TO ioByte                            'one "beep" per count
          FREQOUT pin, 25, ioByte*100+2000  'and  "beeps" for each "digit" are slightly different
          PAUSE 25
       NEXT
       PAUSE 250
       RETURN
    
    



    My number is only four digits, though. How do I alter the code?

    Should it be the following?
    [size=2][code]
    
    
    myNumber VAR Word
    i VAR Nib
    ioByte VAR Byte
    [color=#990000]
       [b]ioByte = myNumber//10000/1000   'get 1000s
       GOSUB Play_Number
       ioByte = myNumber//1000/100   'get 100s[/b]
       GOSUB Play_Number[/color]
       ioByte = myNumber//100/10   'get 10s
       GOSUB Play_Number
       ioByte = myNumber//10   'get 1s
       GOSUB Play_Number
    
    END
    
    'subroutine
    Play_Number:
       FOR i = 1 TO ioByte                            'one "beep" per count
          FREQOUT pin, 25, ioByte*100+2000  'and  "beeps" for each "digit" are slightly different
          PAUSE 25
       NEXT
       PAUSE 250
       RETURN
    
    


    [/code][/size]


    Thanks!

    Post Edited (ghost13) : 6/7/2007 5:36:46 AM GMT
  • ZootZoot Posts: 2,227
    edited 2007-06-07 15:36
    Yeah, that would work. Though if your orig. value will be < 10000 you could do it like this:

    ioByte = myNumber/1000 'get 1000s
    GOSUB Play_Number
    ioByte = myNumber//1000/100 'get 100s
    GOSUB Play_Number
    ioByte = myNumber//100/10 'get 10s
    GOSUB Play_Number
    ioByte = myNumber//10 'get 1s
    GOSUB Play_Number

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
Sign In or Register to comment.