Turning a number into "beeps"
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
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
If you search search.parallax.com, you'll find more on the subject.
but I don't know if it is for BS1 though
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
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
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!
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 RETURNMy 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
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