Shop OBEX P1 Docs P2 Docs Learn Events
Question Re. BS-2 Math — Parallax Forums

Question Re. BS-2 Math

ArchiverArchiver Posts: 46,084
edited 2001-11-06 14:13 in General Discussion
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

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-11-06 05:46
    Jacob you frogot to put the % in front of your variable in debug. It
    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/
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2001-11-06 06:12
    Correction the correct prefix is ,bin, before the variable not %.
    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/
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2001-11-06 14:13
    Jacob -

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