Shop OBEX P1 Docs P2 Docs Learn Events
program to pick from a menu — Parallax Forums

program to pick from a menu

ouconvertouconvert Posts: 17
edited 2006-01-29 07:18 in BASIC Stamp
alright, what i want the stamp to do is prompt the user for one position out of ten, A-J (horizontal movement). And than asks for another position,
0-9 (vertical movement). A-J and 0-1 are constants relating to a position that a stepper motor will go to. im experimenting with a servo motor
right now and im not having much luck. im not using the commands to command a·stepper with the servo so thats not the problem. ·is there a switch function like in C? any input would be great. thanks
sean

Comments

  • ouconvertouconvert Posts: 17
    edited 2006-01-28 00:05
    please dont make fun, i am so new to programming its not funny. whats wrong with this code? i have a standard servo hooked up.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    counter VAR Word
    pulses VAR Bit
    duration VAR Bit
    a CON 500
    k CON 1000

    DO

    DEBUG CLS, "Enter selection of vertical movement, a-j.", CR
    DEBUGIN HEX pulses

    IF pulses = a THEN
    FOR counter = 1 TO a
    PULSOUT 14, k
    PAUSE 20
    NEXT

    DEBUG "Done"
    PAUSE 1000

    ENDIF

    LOOP
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-01-28 00:28
    Ouconvert -

    One of the problems is that the variables that you have defined as BIT need to be defined as BYTE or WORD variables depending on the values they will contain.

    /code

    BIT =·· 0 or 1 ONLY
    BYTE = 0·· ->··· 255
    WORD = 0 -> 65535

    /code

    Regards,

    Bruce Bates
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-28 00:54
    PBASIC 2.5 has SELECT..CASE which is very similar to C's SWITCH structure. There are other tricks, too, that can sometimes be more effective. Things like LOOKDOWN used with ON-GOSUB for example, can be very effective.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • ouconvertouconvert Posts: 17
    edited 2006-01-29 05:39
    im trying to make it work with the code below but it does nothing close to what i want it to do. what am i doing wrong?

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    counter VAR Word
    horizontal VAR Byte
    vertical VAR Byte
    a CON 150
    b CON 150
    c CON 150
    k CON 1000
    l CON 500
    m CON 750

    DO

    DEBUG CLS, "Enter selection of vertical movement, a-j.", CR
    DEBUGIN HEX vertical

    DEBUG "Program running.", CR

    IF vertical = a THEN GOSUB case_0
    IF vertical = b THEN GOSUB case_1
    IF vertical = c THEN GOSUB case_2

    case_0:
    FOR counter = 1 TO 150
    PULSOUT 14, 1000
    DEBUG "Going to 10 o'clock.", CR
    PAUSE 20
    NEXT
    GOTO finishup

    case_1:
    FOR counter = 1 TO 150
    PULSOUT 14, 150
    DEBUG "Going to 2 o'clock.", CR
    PAUSE 20
    NEXT
    GOTO finishup

    case_2:
    FOR counter = 1 TO 150
    PULSOUT 14, 750
    DEBUG "Going to 12 o'clock.", CR
    PAUSE 20
    NEXT
    GOTO finishup

    finishup:
    DEBUG "Done."
    PAUSE 500

    LOOP
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-29 07:18
    I've attached a program that will get two inputs from the user and read the associated counts from DATA tables.· It should help you get going.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.