PDA

View Full Version : program to pick from a menu



ouconvert
01-28-2006, 06:46 AM
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

ouconvert
01-28-2006, 07:05 AM
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 Bates
01-28-2006, 07:28 AM
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 Williams
01-28-2006, 07:54 AM
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

ouconvert
01-29-2006, 12:39 PM
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 Williams
01-29-2006, 02:18 PM
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