Number output to an LCD
Archiver
Posts: 46,084
Gentlemen,
I need your help again.
I can display all the text in the world to the LCD, but it doesnt like
variables (especially with numbers)
I have looked for a conversion instruction, but was unable to find one. I
need to convert a 10 bit ADC to display it on the LCD. Eventually I will
also need to do math on it, but FP numbers are difficult in PBasic.
Thanks,
Mark
I need your help again.
I can display all the text in the world to the LCD, but it doesnt like
variables (especially with numbers)
I have looked for a conversion instruction, but was unable to find one. I
need to convert a 10 bit ADC to display it on the LCD. Eventually I will
also need to do math on it, but FP numbers are difficult in PBasic.
Thanks,
Mark
Comments
string of characters. It's not too tough -- you can use a loop with the DIG
operator to get the individual digit value in each place, then add "0" (ASCII
48) to convert it to a character -- then send it to the LCD.
Here's a code fragment that assumes your number is in a variable called myNum.
WriteNumber:
FOR x = 4 TO 0 ' scan 5 possible digits
in number
char = myNum DIG x + "0" ' convert digit to ASCII code
GOSUB LCDwrite ' write to LCD
NEXT
RETURN
-- Jon Williams
-- Parallax
In a message dated 10/24/01 8:19:22 AM Central Daylight Time,
madams@a... writes:
> I can display all the text in the world to the LCD, but it doesnt like
> variables (especially with numbers)
>
> I have looked for a conversion instruction, but was unable to find one. I
> need to convert a 10 bit ADC to display it on the LCD. Eventually I will
>
[noparse][[/noparse]Non-text portions of this message have been removed]
Now what about dividing a 10 bit number by 0.0733
Mark
Original Message
From: jonwms@a... [noparse]/noparse]SMTP:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=yk9_B4RRV9s9GBLGY-Fierq1lwt8-bS-T3SSRWALJPjfpEqbrnplSV6AroojyPT2XnoDv0_NNA]jonwms@a...[/url
Sent: Wednesday, October 24, 2001 9:05 AM
To: basicstamps@yahoogroups.com
Subject: Re: [noparse][[/noparse]basicstamps] Number output to an LCD
LCDs only display charcters, so to display a number, you must convert it to a
string of characters. It's not too tough -- you can use a loop with the DIG
operator to get the individual digit value in each place, then add "0" (ASCII
48) to convert it to a character -- then send it to the LCD.
Here's a code fragment that assumes your number is in a variable called myNum.
WriteNumber:
FOR x = 4 TO 0 ' scan 5 possible digits
in number
char = myNum DIG x + "0" ' convert digit to ASCII code
GOSUB LCDwrite ' write to LCD
NEXT
RETURN
-- Jon Williams
-- Parallax
In a message dated 10/24/01 8:19:22 AM Central Daylight Time,
madams@a... writes:
> I can display all the text in the world to the LCD, but it doesnt like
> variables (especially with numbers)
>
> I have looked for a conversion instruction, but was unable to find one. I
> need to convert a 10 bit ADC to display it on the LCD. Eventually I will
>
[noparse][[/noparse]Non-text portions of this message have been removed]
To UNSUBSCRIBE, just send mail to:
basicstamps-unsubscribe@yahoogroups.com
from the same email address that you subscribed. Text in the Subject and Body
of the message will be ignored.
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
madams@a... writes:
> Now what about dividing a 10 bit number by 0.0733
>
Dividing by 0.0733 is the same as multiplying by 13.6426. The BASIC Stamp
has an operator called star-slash (*/) that can be used to multiply
fractional values. The fractions are expressed in 1/256. In the case above,
13.6426 * 256 = 3492. Your code, then, is this:
newVal = oldVal */ 3492
You will have to deal with possible rounding and overflow errors. It would
be best to write some test code and DEBUG the results to make sure they're in
line with what you expect.
-- Jon Williams
-- Parallax
PS: Tracy Allen is the undisputed best when it comes to Stamp math and
dealing with high-precision values. You really should visit his site:
http://www.emesys.com/BS2index.htm
[noparse][[/noparse]Non-text portions of this message have been removed]
site) but if you could tolerate 5% error a quick approach is just
multiply by 13.
ACJacques
Mark Adams wrote:
>
> That is exactly what I was looking for, thanks!
>
> Now what about dividing a 10 bit number by 0.0733
>
> Mark
>
>
Original Message
> From: jonwms@a... [noparse]/noparse]SMTP:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=NCX4Svf6gA49C9mSheu1RxswrjAKmNCEbJbPNTUZCO4aJLXUxSFq91KRcRmfkPpUObCjFt3kWhs]jonwms@a...[/url
> Sent: Wednesday, October 24, 2001 9:05 AM
> To: basicstamps@yahoogroups.com
> Subject: Re: [noparse][[/noparse]basicstamps] Number output to an LCD
>
> LCDs only display charcters, so to display a number, you must convert it to a
> string of characters. It's not too tough -- you can use a loop with the DIG
> operator to get the individual digit value in each place, then add "0" (ASCII
> 48) to convert it to a character -- then send it to the LCD.
>
> Here's a code fragment that assumes your number is in a variable called myNum.
>
> WriteNumber:
> FOR x = 4 TO 0 ' scan 5 possible digits
> in number
> char = myNum DIG x + "0" ' convert digit to ASCII code
> GOSUB LCDwrite ' write to LCD
> NEXT
> RETURN
>
> -- Jon Williams
> -- Parallax
>
> In a message dated 10/24/01 8:19:22 AM Central Daylight Time,
> madams@a... writes:
>
> > I can display all the text in the world to the LCD, but it doesnt like
> > variables (especially with numbers)
> >
> > I have looked for a conversion instruction, but was unable to find one. I
> > need to convert a 10 bit ADC to display it on the LCD. Eventually I will
> >
>
> [noparse][[/noparse]Non-text portions of this message have been removed]
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the Subject and Body
of the message will be ignored.
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the Subject and Body
of the message will be ignored.
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
PAK-I, II, and IX all of which do floating point math.
http://www.al-williams.com/awce/pak1.htm
Regards,
Al Williams
AWC
* 8 channels of PWM
http://www.al-williams.com/awce/pak5.htm
>
Original Message
> From: Mark Adams [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=1AAIwdRKbCWoRWlT2AdyUroyAF3djF2MCHJXd0oloE_E2jzIRVnfGLClAfysrV8Tzho2RBCASD-t2Q]madams@a...[/url
> Sent: Wednesday, October 24, 2001 9:14 AM
> To: 'basicstamps@yahoogroups.com'
> Subject: RE: [noparse][[/noparse]basicstamps] Number output to an LCD
>
>
> That is exactly what I was looking for, thanks!
>
> Now what about dividing a 10 bit number by 0.0733
>
> Mark
>
>
Original Message
> From: jonwms@a... [noparse]/noparse]SMTP:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=5cHLhWf_5rwKhcZmXJpel0ZtXObKeAi8DCiE3Sh_cPAGyLjkd8nuLRAoyPd2g6D5so9KWdM]jonwms@a...[/url
> Sent: Wednesday, October 24, 2001 9:05 AM
> To: basicstamps@yahoogroups.com
> Subject: Re: [noparse][[/noparse]basicstamps] Number output to an LCD
>
> LCDs only display charcters, so to display a number, you must
> convert it to a
> string of characters. It's not too tough -- you can use a loop
> with the DIG
> operator to get the individual digit value in each place, then
> add "0" (ASCII
> 48) to convert it to a character -- then send it to the LCD.
>
> Here's a code fragment that assumes your number is in a variable
> called myNum.
>
> WriteNumber:
> FOR x = 4 TO 0 ' scan 5
> possible digits
> in number
> char = myNum DIG x + "0" ' convert digit to
> ASCII code
> GOSUB LCDwrite ' write to LCD
> NEXT
> RETURN
>
>
> -- Jon Williams
> -- Parallax
>
>
>
> In a message dated 10/24/01 8:19:22 AM Central Daylight Time,
> madams@a... writes:
>
>
> > I can display all the text in the world to the LCD, but it doesnt like
> > variables (especially with numbers)
> >
> > I have looked for a conversion instruction, but was unable to
> find one. I
> > need to convert a 10 bit ADC to display it on the LCD.
> Eventually I will
> >
>
>
>
>
> [noparse][[/noparse]Non-text portions of this message have been removed]
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the
> Subject and Body of the message will be ignored.
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the
> Subject and Body of the message will be ignored.
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>madams@a... writes:
>
>
> > Now what about dividing a 10 bit number by 0.0733
> >
>
>Dividing by 0.0733 is the same as multiplying by 13.6426. The BASIC Stamp
>has an operator called star-slash (*/) that can be used to multiply
>fractional values. The fractions are expressed in 1/256. In the case above,
>13.6426 * 256 = 3492. Your code, then, is this:
>
> newVal = oldVal */ 3492
>
>You will have to deal with possible rounding and overflow errors. It would
>be best to write some test code and DEBUG the results to make sure they're in
>line with what you expect.
>
>-- Jon Williams
>-- Parallax
>
>PS: Tracy Allen is the undisputed best when it comes to Stamp math and
>dealing with high-precision values. You really should visit his site:
>
> http://www.emesys.com/BS2index.htm
Thanks for the boost, Jon!
The best precision easily comes from the ** operator. It expresses
fractions in units of 1/65536, which is in general more accurate than
1/256. But ** can only do fractions between zero and one, so it
takes two steps on the Stamp:
newVal = (oldval * 13) + (oldVal ** 42111)
0.6425648 * 65536 = 42111
that is to say, 42111/65536 is close to 0.6425648, within better than
4 decimal places. With a ten bit number for oldval, it is not going
to overflow. That is, the maximum value 1024/0.0733 is 13970, less
than one word in value. The new value has more significant digits
than the old value, so you could probably round off the last digit.
The ** operator gives you the extra precision to allow accurate
rounding.
-- regards,
Tracy Allen
electronically monitored ecosystems
mailto:tracy@e...
http://www.emesystems.com