Shop OBEX P1 Docs P2 Docs Learn Events
Freshman in Basic Stamp — Parallax Forums

Freshman in Basic Stamp

philip88822philip88822 Posts: 11
edited 2009-03-06 00:25 in Learn with BlocklyProp
Hello Everybody
I am a freshman in Basic Stamp and i want to know what is the code of the following question

Questions:
Display the message “ Please Key in S to start ” in the Debug Terminal and prompt the user to key in letter S.·· Display the message “ Wrong letter ” in the Debug Terminal and prompt the user to key in again when the input is not S.·· If the input is True , then display the message “ Right letter ” in the Debug Terminal.

Thx a lot

Philip

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-03 15:08
    Read the Basic Stamp Syntax and Reference Manual chapters on the DEBUG and DEBUGIN statements and you should be able to figure this out.
    Another good source for information is the "What's a Microcontroller?" tutorial. These can all be downloaded from Parallax. Go to their main webpage
    and click on the Resources tab. You'll see a list of resources. Choose Downloads, then Stamps in Class Downloads to find the tutorials. From
    Downloads, choose BASIC Stamp Documentation for a link to the Reference Manual.

    This sounds like a project for a class and you need to do that yourself in order to learn properly.
  • philip88822philip88822 Posts: 11
    edited 2009-03-03 15:33
    Thx
    But i want to know the correct code as i don;t know am i correct or not
    Also, i want to ask is there any way to check out the program is work or not without the stamp?

    Post Edited (philip88822) : 3/3/2009 3:38:38 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-03 15:48
    There is a BS2 simulator available, but it is not free (www.labcenter.co.uk/products/bstamp.cfm). There's no other way to check out a program to see whether it will work except to try it on a Stamp. I've seen some free Stamp simulators on the internet, but they're for a different Stamp model (BS1) which doesn't have the ability to input from the debug window (among other things).
  • philip88822philip88822 Posts: 11
    edited 2009-03-03 16:17
    Mike Green said...
    There is a BS2 simulator available, but it is not free (www.labcenter.co.uk/products/bstamp.cfm). There's no other way to check out a program to see whether it will work except to try it on a Stamp. I've seen some free Stamp simulators on the internet, but they're for a different Stamp model (BS1) which doesn't have the ability to input from the debug window (among other things).
    Can u tell me what is the code of the answer?
    I·have already download the DOC that you told me to download
    But i am not·sure that i·understand or not
    THANK YOU VERY MUCH
  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-03 16:44
    If there are specific things you don't understand, I will be happy to help explain them, but I will not do the work for you. As with any programming, you start with the statement of the problem and break it down into steps. Your statement in the 1st message here is already broken down into steps. The references I mentioned explain how to do many of the steps like displaying messages and entering characters. The IF statement is used for testing values and there are plenty of examples of its use in both references.

    If English is not your native language, there are translations of both of these references also available on the same webpages I mentioned.
  • UghaUgha Posts: 543
    edited 2009-03-04 03:49
    As Mike Green said, this sounds like its for class so you are·not likely to find someone to do it for you here.
    If you post the code you already have then I'm sure Mike, myself, or one of the other wonderful people who help others on these forums will be glad to
    guide you into fixing your code.

    You may attach your code by clicking Post Reply then using the Attachment manager to upload your code.

    The things you need to research are:
    Variables
    IF statements
    DEBUG command
    DEBUGIN command

    All the needed information on these are available in the Basic Stamp editor's helpfile and also in the "What's a Microcontroller" book. You can also find the
    information in "Robotics with the BOE-Bot".

    All of which are available as free downloads on the Parallax site. Go to www.Parallax.com and click on Support then Basic Stamp Documentation for the books
    or Basic Stamp Software for the editor. As Mike said, there are several translations of the various books and several versions of the software for PC, Mac and
    Linux.

    You now have all of the information and direction needed to answer your question. If you need further help that does not involve someone doing your homework
    for you, then feel free to ask.

    Post Edited (Ugha) : 3/4/2009 3:55:16 AM GMT
  • philip88822philip88822 Posts: 11
    edited 2009-03-04 13:43
    I think that the code is:

    MyNum VAR Nib<
    What is the use of this?
    DEBUG CLS, "Please Key in S to start"<----What is the meaning of CLS?
    DEBUGIN DEC1 myNum<
    IF ((myNum = S) THEN
    DEBUG CLS, "Right Letter·"
    ELSE
    DEBUG CLS, "Wrong letter"
    ENDIF
    END

    Is there anythings that i need to change?
    Thx for help

    ·
  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-04 14:43
    "Nib" (nibble) refers to a 4 bit value. "Byte" refers to an 8 bit value, and "Word" refers to a 16 bit value. Along with "Bit", these are the basic storage units in the Stamp (and most microprocessors).

    "MyNum VAR Nib" tells the compiler to set aside (declare) space for a 4 bit value and give it a name "MyNum" for use elsewhere in the program.

    In your case, you want to use a byte rather than a nibble because the values you will store (characters) are 8 bits.

    "CLS" is a predefined name for a character that will clear the debug window when sent by a DEBUG or SEROUT statement to the debug window. There's a table in the manual of this and other predefined names. Read the chapter on the DEBUG statement for this.

    "DEBUGIN DEC1 myNum" uses what's called a formatter (DEC1) to process the input characters from the debug window. There's a description of all the formatters in the chapter on the DEBUGIN statement and in Appendix C. If you don't use a formatter, the next character's ASCII code value is put into variable. In your case, that's probably what you want (leave out the DEC1).

    The IF statement you wrote won't work for 2 reasons:
    1) The parentheses are not balanced. You don't need them anyway.

    2) You're comparing myNum to S and S isn't defined anywhere. As you've written it, it's a name just like myNum. You probably want to put quotes around it. Read the section of the manual on constants, expressions, and number representations (pages 94-98).

    It's a lot to go through, but you really have to read through the "What's a Microcontroller?" tutorial and the introductory parts of the Stamp Manual.

    Post Edited (Mike Green) : 3/4/2009 2:49:10 PM GMT
  • philip88822philip88822 Posts: 11
    edited 2009-03-05 05:48
    DIRA=0
    DIRB=15
    DIRC=15
    DIRD=15
    OUTC=0

    A VAR BYTE
    MAIN:
    A=0
    DEBUG “PLEASE KEY IN S TO START!” , CR
    SERIN 16,16468,[noparse][[/noparse]A]

    IF A=”S” THEN CORRECT
    IF NOT (A=”S&#8221[noparse];)[/noparse] THEN INCORRECT

    CORRECT:
    DEBUG “RIGHT LETTER” ,CR
    GOTO MAIN

    INCORRECT:
    DEBUG “Wrong Letter”
    Goto main

    How about this code
    Does it work?
  • SRLMSRLM Posts: 5,045
    edited 2009-03-05 07:21
    Well, we can break it down by following how the program executes. It starts by defining values for registers and making a byte. It then prompts for user input, and tests that input. Based on the input, it breaks to a subroutine, and then returns to take new user input.
  • philip88822philip88822 Posts: 11
    edited 2009-03-05 12:29
    It means that this code work properly, right?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-06 00:25
    The only way to tell if the code works properly is to enter it into the Stamp Editor, successfully compile it, then download it to a Stamp and try it out.

    What you posted looks like it should do what you want
Sign In or Register to comment.