Hard Task in need of assistance
rawr
Posts: 4
My robot will have three pushbuttons and three LEDs; red, yellow, and green.· My program will make my robot go fast and have a green LED go on, when the go button is pressed.· It will continue to do this task until another button is pressed.· My robot will go slower when the yellow button is pressed.· It will continue to do this task until another button is pressed.·
My Question is what commands do i use... if else, if than, else?
Please help me get my program off the drawing board.
·
My Question is what commands do i use... if else, if than, else?
Please help me get my program off the drawing board.
·
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
Main:
· DO
··· GOSUB Scan_Buttons
··· IF (buttons > 0) THEN
···· ·temp = $F
···· ·LOOKDOWN buttons, [noparse][[/noparse]%001, %010, %100], temp
···· ·IF (temp <> $F) THEN mode = temp
··· ENDIF
··· ON mode GOSUB Mode_0, Mode_1, Mode_2
· LOOP
Mode_0:
··GreenLed = On
· YellowLed = Off
··RedLed = Off
· RETURN
Mode_1:
··GreenLed =·Off
· YellowLed = On
··RedLed = Off
· RETURN
Mode_2:
··GreenLed =·Off
· YellowLed = Off
··RedLed = On
· RETURN
Scan_Buttons:
· buttons = %0111··············· ' assume pressed
· FOR idx = 1 TO·4·············· ' debounce for 20 mS
··· buttons = buttons & ~INA···· ' active-low inputs on INA
··· PAUSE 5
· NEXT
· RETURN
that's the program you gave me.· How will I add a Mode_3?
DO
GOSUB Scan_Buttons
IF (buttons > 0) THEN
temp = $F
LOOKDOWN buttons, [noparse][[/noparse]%001, %010, %100,%1000], temp
IF (temp <> $F) THEN mode = temp
ENDIF
ON mode GOSUB Mode_0, Mode_1, Mode_2, Mode_3
LOOP
Mode_0:
GreenLed = On
YellowLed = Off
RedLed = Off
RETURN
Mode_1:
GreenLed = Off
YellowLed = On
RedLed = Off
RETURN
Mode_2:
GreenLed = Off
YellowLed = Off
RedLed = On
RETURN
Mode_3:
GreenLed = Off
YellowLed = Off
RedLed = Off
RETURN
Scan_Buttons:
buttons = %1111 ' assume pressed
FOR idx = 1 TO 4 ' debounce for 20 mS
buttons = buttons & ~INA ' active-low inputs on INA
PAUSE 5
NEXT
RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
League Bowling.... it's not a sport, it's a way of life
Post Edited (nick bernard) : 12/7/2004 2:20:30 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
League Bowling.... it's not a sport, it's a way of life
'{$PBASIC 2.5}
red VAR IN0
yellow VAR IN3
green VAR IN6
crash VAR IN9
counter VAR Word
Main:
DO
GOSUB Scan_Buttons
IF (buttons > 0) THEN
temp = $F
LOOKDOWN buttons, [noparse][[/noparse]%001, %010, %100,%1000], temp
IF (temp <> $F) THEN mode = temp
ENDIF
ON mode GOSUB Green, Yellow, Red, Crash
LOOP
Green:
HIGH 6
DEBUG "Green", CR
FOR COUNTER = 1 TO 375
PULSOUT 15, 50
PULSOUT 14, 1500
NEXT
RETURN
Yellow:
HIGH 3
DEBUG "Yellow", CR
FOR COUNTER = 1 TO 375
PULSOUT 15, 50
NEXT
RETURN
Red:
DEBUG "Red", CR
STOP
RETURN
Crash:
DEBUG "Crash", CR: FREQOUT 9, 1000, 1568
RETURN
Scan_Buttons:
buttons = %1111 ' assume pressed
FOR idx = 1 TO 4 ' debounce for 20 mS
buttons = buttons & ~INA ' active-low inputs on INA
PAUSE 5
NEXT
RETURN
how come buttons is an unidentified symbol??? plz resond quickly.
The simple and obvious answer as to why it's being flagged as undefined, is that it wasn't defined before it was used. It's customary to define all the variables and constants that you are going to use in your program at or near the beginning of your program. Adding the following definition will eliminate that particular errror, but there are many others in the program:
buttons· var· ·nib· 'allocate 4 bits of RAM for button state
Just as an observation a good deal was changed in this program from when Jon originally supplied it. Notable among the changes which are about to cause you trouble, are the changes below (as examples):
Former····· Latter········· Comment
······
··········
redled··· -> red····redled was unique, red now defined both as var name + program label
greenled-> green· greenled was unique, green now defined both as var name + program label.
Other changes similar to those were also made. You may want to just go back to the original program that Jon provided,·and make your changes again. A good deal was lost in the last alteration process.
Regards,
Bruce Bates