Question Re. BS-2 Math
Archiver
Posts: 46,084
Hi!!! Thanks to all who responded to my last question regarding the
conversion from decimal to ASCII. Now, I have another question. My
project does a math problem that is executed when a pushbutton switch
is pressed. Here it is:
zero: 'executed if pb 0 is hit
ans1 = ans1 * 10 'does some math stuff to ans1
one: 'executed if pb 1 is hit
ans1 = ans1 * 10 'does some math stuff to ans1
ans1 = ans1 + 1
The ans1 variable is always set to 0 before use. The zero and one
sections are executed about twice each in the program. But, when the
variable ans1 is read in debug (debug dec ans1), the answer is a
number from 240-250. The answer should be a binary-like number (all
zeros and ones). What could I be doing wrong? Thank you for your
help.
Jacob
conversion from decimal to ASCII. Now, I have another question. My
project does a math problem that is executed when a pushbutton switch
is pressed. Here it is:
zero: 'executed if pb 0 is hit
ans1 = ans1 * 10 'does some math stuff to ans1
one: 'executed if pb 1 is hit
ans1 = ans1 * 10 'does some math stuff to ans1
ans1 = ans1 + 1
The ans1 variable is always set to 0 before use. The zero and one
sections are executed about twice each in the program. But, when the
variable ans1 is read in debug (debug dec ans1), the answer is a
number from 240-250. The answer should be a binary-like number (all
zeros and ones). What could I be doing wrong? Thank you for your
help.
Jacob
Comments
means return digit in binary form.
On Tue, 06 Nov 2001 05:17:24 -0000 sejpower@j... writes:
> Hi!!! Thanks to all who responded to my last question regarding the
> conversion from decimal to ASCII. Now, I have another question. My
>
> project does a math problem that is executed when a pushbutton
> switch
> is pressed. Here it is:
>
> zero: 'executed if pb 0 is hit
> ans1 = ans1 * 10 'does some math stuff to ans1
>
> one: 'executed if pb 1 is hit
> ans1 = ans1 * 10 'does some math stuff to ans1
> ans1 = ans1 + 1
>
> The ans1 variable is always set to 0 before use. The zero and one
> sections are executed about twice each in the program. But, when
> the
> variable ans1 is read in debug (debug dec ans1), the answer is a
> number from 240-250. The answer should be a binary-like number (all
>
> zeros and ones). What could I be doing wrong? Thank you for your
> help.
> Jacob
>
>
> 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/
>
>
Sorry, I souldn't stay up so late.
On Tue, 06 Nov 2001 05:17:24 -0000 sejpower@j... writes:
> Hi!!! Thanks to all who responded to my last question regarding the
> conversion from decimal to ASCII. Now, I have another question. My
>
> project does a math problem that is executed when a pushbutton
> switch
> is pressed. Here it is:
>
> zero: 'executed if pb 0 is hit
> ans1 = ans1 * 10 'does some math stuff to ans1
>
> one: 'executed if pb 1 is hit
> ans1 = ans1 * 10 'does some math stuff to ans1
> ans1 = ans1 + 1
>
> The ans1 variable is always set to 0 before use. The zero and one
> sections are executed about twice each in the program. But, when
> the
> variable ans1 is read in debug (debug dec ans1), the answer is a
> number from 240-250. The answer should be a binary-like number (all
>
> zeros and ones). What could I be doing wrong? Thank you for your
> help.
> Jacob
>
>
> 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/
>
>
Three potential problems:
1) You can only ever have five button presses counting
from the first press of pb 1 and still stay within the
limits of a word variable. E.g. pb0 pb1 pb0 pb1 pb0
pb1 yields 10101, a decimal number. Any more button
presses and you exceed 65535 and get unexpected
(though technically not unpredictable) results.
2) If your code is as displayed, then every time
function "zero" is executed, control drops into
function "one," then presumably back to the main loop
where you look for button presses.
3) Depending how you implement your button monitoring,
you could press a button momentarily but have your
program see the condition as true multiple times. The
"if pb1 = 1 then one" statement in your main loop goes
true, executes function "one", and returns to the main
loop; but only a few milliseconds have passed and the
button is still pressed so the process of calling
"one" repeats many times in what seems to you a very
quick button press.
Good luck!
Bob Pence
--- sejpower@j... wrote:
> Hi!!! Thanks to all who responded to my last
> question regarding the
> conversion from decimal to ASCII. Now, I have
> another question. My
> project does a math problem that is executed when a
> pushbutton switch
> is pressed. Here it is:
>
> zero: 'executed if pb 0 is hit
> ans1 = ans1 * 10 'does some math stuff to ans1
>
> one: 'executed if pb 1 is hit
> ans1 = ans1 * 10 'does some math stuff to ans1
> ans1 = ans1 + 1
>
> The ans1 variable is always set to 0 before use.
> The zero and one
> sections are executed about twice each in the
> program. But, when the
> variable ans1 is read in debug (debug dec ans1), the
> answer is a
> number from 240-250. The answer should be a
> binary-like number (all
> zeros and ones). What could I be doing wrong?
> Thank you for your
> help.
> Jacob
>
>
> 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/
>
>
__________________________________________________
Do You Yahoo!?
Find a job, post your resume.
http://careers.yahoo.com