I guess your first task is to figure out what you want it to do then break that down into steps and figure out what the computer needs to do to accomplish that.
Take a look at the code I posted here for ideas. It controls a BOE-BOT, but, if you take out the RF link stuff, then the code does essentially what you want.
If you need a place to start, get this book (there are two volumes, you want the first):
The Microcontroller Application Cookbook (Microcontroller Application Cookbooks) (Paperback)
by Matt Gilliland (Author)
Its a great book that breaks down input/output/control very and makes it very easy because the code examples are very brief. Even better for you, they are written in PBASIC which is your stamp's language. Of special interest to you should be the details on circuit protection.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Thomas Talbot, MD
Gunpowder, MD, USA
I tried a code (but did not work) the debug would only accept 02
' {$STAMP BS2}
' {$PBASIC 2.5}
direction VAR Word
DEBUG "enter direction ",CR
DEBUGIN DEC direction
DO
IF (direction = 02) THEN
HIGH 0
HIGH 2
IF (direction = 01) THEN
HIGH 0
HIGH 3
IF (direction = 00) THEN
LOW 0
IF (direction = 1) THEN
HIGH 1
IF (direction = 0) THEN
HIGH 0
IF (direction = 11) THEN
HIGH 1
HIGH 2
IF (direction = 12) THEN
HIGH 1
HIGH 3
PAUSE 1000
You'll want to use the SELECT...CASE structure instead of all of those nested IF-THENs. It'll clean things up considerably.
Take a look in the Basic Stamp Manual online.
well i could not get select-case structure to work but i did get elseif to work
(program still has the problems)
' {$STAMP BS2}
' {$PBASIC 2.5}
direction VAR Word
DO
DEBUG "enter direction ",CR
DEBUGIN DEC direction
IF (direction = 02) THEN
HIGH 0
HIGH 2
ELSEIF ( direction = 03) THEN
HIGH 0
HIGH 3
ELSEIF (direction = 00) THEN
LOW 0
ELSEIF (direction = 1) THEN
HIGH 1
ELSEIF (direction = 0) THEN
HIGH 0
ELSEIF (direction = 11) THEN
HIGH 1
HIGH 2
ELSEIF (direction = 12) THEN
HIGH 1
HIGH 3
PAUSE 1000
DEBUGIN direction : direction =00
You have listed seven different evaluations for the variable "direction". Since the value 0 is the same as 00 then you are really only evaluating six. "ELSEIF (direction = 0) THEN" never gets evaluated because "ELSEIF (direction = 00) THEN" is identical logic. This IF-THEN-ELSEIF structure will find the first (and only the first) TRUE statement and execute the code block for that statement only.
The SELECT-CASE should work for you as well. A common mistake is using the "=" between CASE and the variable
you are evaluating. This is the syntax:
SELECT direction
CASE 0 THEN ' don't use equal sign
HIGH 0
CASE 1 THEN
HIGH 1
.
.
.
ENDSELECT
· Also, your program won't loop because you have an END statement within your loop structure.· Did you mean to end your IF-THEN-ELSEIF structure with this?· You should remove END.
Post Edited (Mikerocontroller) : 11/15/2008 4:00:37 AM GMT
ok that cleaned it up alot and the rest of the the selection works
but the program only excepts one direction then has to be reset-any ideas?
' {$STAMP BS2}
' {$PBASIC 2.5}
direction VAR Word
DO
DEBUG "enter direction ",CR
DEBUGIN DEC direction
SELECT direction
CASE 0
HIGH 0
CASE 1
HIGH 1
CASE 2
HIGH 2
CASE 3
HIGH 3
CASE 4
HIGH 4
ENDSELECT
LOOP
· Are you controlling motors or servos? Please post schematics or more detailed info.· Your code is sound but it looks like it won't suit your purpose.
Also, the pins will stay·HIGH once you set them.· If your program doesen't change their state they will stay that way.
Don't drive any kind of motor directly from the Stamp pins.
Post Edited (Mikerocontroller) : 11/17/2008 3:16:32 AM GMT
Also note that if you are posting formatted code, it's best to use the code option in order to keep the format. It's difficult to quickly read unformatted code.
· You really should consider getting some kind of motor controller for this project.·· Your·setup right now has pin 3 of the Stamp controlling the emitter current of all those transistors.· That will most definitely damage your microcontroller .·
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
but using the debug terminal as the input
The Microcontroller Application Cookbook (Microcontroller Application Cookbooks) (Paperback)
by Matt Gilliland (Author)
Its a great book that breaks down input/output/control very and makes it very easy because the code examples are very brief. Even better for you, they are written in PBASIC which is your stamp's language. Of special interest to you should be the details on circuit protection.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Thomas Talbot, MD
Gunpowder, MD, USA
I tried a code (but did not work) the debug would only accept 02
' {$STAMP BS2}
' {$PBASIC 2.5}
direction VAR Word
DEBUG "enter direction ",CR
DEBUGIN DEC direction
DO
IF (direction = 02) THEN
HIGH 0
HIGH 2
IF (direction = 01) THEN
HIGH 0
HIGH 3
IF (direction = 00) THEN
LOW 0
IF (direction = 1) THEN
HIGH 1
IF (direction = 0) THEN
HIGH 0
IF (direction = 11) THEN
HIGH 1
HIGH 2
IF (direction = 12) THEN
HIGH 1
HIGH 3
PAUSE 1000
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
END
LOOP
Take a look in the Basic Stamp Manual online.
(program still has the problems)
' {$STAMP BS2}
' {$PBASIC 2.5}
direction VAR Word
DO
DEBUG "enter direction ",CR
DEBUGIN DEC direction
IF (direction = 02) THEN
HIGH 0
HIGH 2
ELSEIF ( direction = 03) THEN
HIGH 0
HIGH 3
ELSEIF (direction = 00) THEN
LOW 0
ELSEIF (direction = 1) THEN
HIGH 1
ELSEIF (direction = 0) THEN
HIGH 0
ELSEIF (direction = 11) THEN
HIGH 1
HIGH 2
ELSEIF (direction = 12) THEN
HIGH 1
HIGH 3
PAUSE 1000
DEBUGIN direction : direction =00
ENDIF
END
LOOP
The SELECT-CASE should work for you as well. A common mistake is using the "=" between CASE and the variable
you are evaluating. This is the syntax:
SELECT direction
CASE 0 THEN ' don't use equal sign
HIGH 0
CASE 1 THEN
HIGH 1
.
.
.
ENDSELECT
· Also, your program won't loop because you have an END statement within your loop structure.· Did you mean to end your IF-THEN-ELSEIF structure with this?· You should remove END.
Post Edited (Mikerocontroller) : 11/15/2008 4:00:37 AM GMT
but the program only excepts one direction then has to be reset-any ideas?
' {$STAMP BS2}
' {$PBASIC 2.5}
direction VAR Word
DO
DEBUG "enter direction ",CR
DEBUGIN DEC direction
SELECT direction
CASE 0
HIGH 0
CASE 1
HIGH 1
CASE 2
HIGH 2
CASE 3
HIGH 3
CASE 4
HIGH 4
ENDSELECT
LOOP
Also, the pins will stay·HIGH once you set them.· If your program doesen't change their state they will stay that way.
Don't drive any kind of motor directly from the Stamp pins.
Post Edited (Mikerocontroller) : 11/17/2008 3:16:32 AM GMT
i had used relays
5v .002a