Shop OBEX P1 Docs P2 Docs Learn Events
Help: Mathematic Project. — Parallax Forums

Help: Mathematic Project.

sthompson86sthompson86 Posts: 2
edited 2010-08-28 11:36 in Learn with BlocklyProp
Hello all, I am in a microcontroller class this semester, and the class is using the Parallax Basic Stamp as the device we learn on. This is the teachers first semester to teach using the Basic Stamp as the device, therefore, we are the pilot class. The teacher let us know he would be asking us to do some extra things with the PBASIC that may not be in the book. ( which is what I am getting to)

Nonetheless, the teacher asked us to do what I thought would be a simple math programming function.

The requested project is the teachers custom version of the Debug Formatters and Control Characters on page 25 of the "What is a Microcontroller" book Ver. 2.2

The whole class was able to successfully complete the books project of adding 7 * 11 , and the teachers requested " 7 * 11 + 24 -1 " he just wanted to run a series of math functions in one line of code. EASY.

HARD - Then he asked all of us to compile something like this. He wanted us to take

7 * 11 + 24 - 1 which equals 100 and then in the next code line take the answer of the "7 * 11 + 24 - 1" (100) and add that 100 to another line of code with more mathematic functions.

something like this:

7 * 11 + 24 - 1 = Var1
Var1 + 2 - 1

= 101

He just wanted us to compile 2 problems into Vs stringing the whole thing out into 1 line of code.

THe class spent 2 whole class periods trying to figure this out, and the teacher didnt even know how to do it. Nonetheless, he said he didnt know, but he would give the points to anybody who could figure it out.

I know I am the only one who is going to the extent and ask the Parallax forums, so I hope to be the one to get things figured out for the class.

I am asking for help, I am no programmer and this is my first taste of it.

Any help is appreciated - Thanks

Comments

  • FranklinFranklin Posts: 4,747
    edited 2010-08-28 11:34
    Take a look in the help files of the editor for "language reference" > "pbasic operators" > "operator presidence"
  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-28 11:36
    You want to use what's called an assignment statement. In Basic, this optionally begins with LET, so it's documented as a LET statement. There's a few pages on this in the Stamp Basic Manual and in the help files of the Stamp Editor. Start there. You'll also need to learn how to declare a variable with a VAR statement. This is in a separate section of the Manual and the help files.

    Essentially, the LET statement stores the value on the right side of the "=" into a 16-bit (two byte) area of the Stamp's memory where it stays until it's changed or until the Stamp is reset or power is turned off. Later in your program, you can refer to this saved (variable) value by name.

    When combining two expressions into one, you probably want to use parentheses. If you have one expression like "5 + 4" and you want to embed it into an expression like "25 * X" where the "X" is where you want the other expression, you'd surround the "5 + 4" with parentheses and substitute the whole thing for the "X" like "25 * (5 + 4)".
Sign In or Register to comment.