R/C controlled Hummer Spy Cam
I am trying to use a basic stamp 2 OEM to control the motor functions of left, right, forward and reverse. I disconnected the four wires to the motors and intend to have them as inputs to my basic stamp. Then I want to send out four outputs to the motors from the basic stamp. So far I have written the code but was wondering if someone can take a look at it for me to see if im missing anything or something is wrong. Programming is not my strongpoint.
' ==============================================================================
'
' File......
' Purpose...basic stamp control of Hummer motor functions.
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' ==============================================================================
'
' Program Description
'
'Control Hummer using 2-Channel R/C
'
' Constants
'
state CON 1
'
' I/O Definitions
'
Ch1 PIN 12 ' Channel used to receive up
Ch2 PIN 1 ' Channel used to drive forward
Ch3 PIN 13 ' Channel used to recieve back
Ch4 PIN 2 ' Channel used to drive reverse1
Ch5 PIN 14 ' Channel used to receive LT
Ch6 PIN 3 ' Channel used to steer left
Ch7 PIN 15 ' Cannel used to receive RT
Ch8 PIN 4 ' Channel used to steer right
'
' Variables
'
up VAR Word
forward VAR Word
back VAR Word
reverse1 VAR Word
LT VAR Word
left VAR Word
RT VAR Word
right VAR Word
'
' Program Code|
'
begin:
DO
PULSIN Ch1 , state , up
PULSIN Ch3 , state , back
PULSIN Ch5 , state , LT
PULSIN Ch7 , state , RT
IF up THEN PULSOUT Ch2 , 100
IF back THEN PULSOUT Ch4 , 100
IF LT THEN PULSOUT Ch6 , 100
IF RT THEN PULSOUT Ch8 , 100
LOOP
' ==============================================================================
'
' File......
' Purpose...basic stamp control of Hummer motor functions.
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' ==============================================================================
'
' Program Description
'
'Control Hummer using 2-Channel R/C
'
' Constants
'
state CON 1
'
' I/O Definitions
'
Ch1 PIN 12 ' Channel used to receive up
Ch2 PIN 1 ' Channel used to drive forward
Ch3 PIN 13 ' Channel used to recieve back
Ch4 PIN 2 ' Channel used to drive reverse1
Ch5 PIN 14 ' Channel used to receive LT
Ch6 PIN 3 ' Channel used to steer left
Ch7 PIN 15 ' Cannel used to receive RT
Ch8 PIN 4 ' Channel used to steer right
'
' Variables
'
up VAR Word
forward VAR Word
back VAR Word
reverse1 VAR Word
LT VAR Word
left VAR Word
RT VAR Word
right VAR Word
'
' Program Code|
'
begin:
DO
PULSIN Ch1 , state , up
PULSIN Ch3 , state , back
PULSIN Ch5 , state , LT
PULSIN Ch7 , state , RT
IF up THEN PULSOUT Ch2 , 100
IF back THEN PULSOUT Ch4 , 100
IF LT THEN PULSOUT Ch6 , 100
IF RT THEN PULSOUT Ch8 , 100
LOOP
Comments
There's nothing wrong with the way you have coded it, but you may experience unnecessary delays. You might want to change it around, as follows:
begin:
DO
PULSIN Ch1 , state , up
IF up THEN PULSOUT Ch2 , 100
PULSIN Ch3 , state , back
IF back THEN PULSOUT Ch4 , 100
PULSIN Ch5 , state , LT
IF LT THEN PULSOUT Ch6 , 100
PULSIN Ch7 , state , RT
IF RT THEN PULSOUT Ch8 , 100
LOOP
This way, as soon as you see that you have a command, you pump it back out instead of checking all of the channels first. This presumes that you have the time to do it this way. If you don't, then the way you have it fine.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
I was a little bit skeptical at first. I can definately save a little time by rearanging the code. Does anyone else have any suggestions?
·
' Program Code|
'
begin:
DO
INPUT Ch1
IF·cH1 THEN OUTPUT Ch2
INPUT Ch3
IF·Ch3 THEN OUTPUT Ch4
INPUT Ch5
IF·Ch5 THEN OUTPUT Ch6
INPUT Ch7
IF·Ch7 THEN OUTPUT Ch8
LOOP
What do you all think????
Time to download the PBASIC Manual I think. if you haven't done so already. Merely documenting the program should show you the problem. Here is just one segemnt, since they're all essentially the same:
INPUT Ch1 'Set Ch1 to Input mode
IF Ch1 THEN OUTPUT Ch2 'If there is Ch1 activity, set Ch2 to output (this sends NOTHING to the port!)
Better to use something like this:
Input Ch1 'Set pin mode to input
IF Ch1 then HIGH Ch2 'If there is Ch1 activity, set Ch2 to output mode and send a 1
Presuming all you wanted to do was to set the ouput pin high.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->