Tank project
stillmatic
Posts: 1
I'm new to basic stamp programming and I'm building an rc tank. I'm hoping some knowledgeable members can check my code and left me know if I'm on the right track.· The remote control connected to the transmitter will be·a basic·forward,·reverse, left, and right control.· When a left or right button is pressed,·I want the tank to pivot·either left or right on itself.· The basic stamp chip is connected to an h-bridge for 2 motors.· Any feedback·is appreciated.··Thanks!·
' {$STAMP BS2} ' {$PBASIC 2.5} ' '******************************************************** '* pin 1 and 2 = motor 1 [noparse][[/noparse]LEFT] directional controls * '* * '* pin 3 = Enable for motor 1 * '* * '* pin 4 and 5 = motor 2 [noparse][[/noparse]RIGHT] directional controls * '* * '* pin 6 = Enable for motor 2 * '******************************************************** '******************setup****************** Left_motor_forward PIN 1 Left_motor_reverse PIN 2 Left_motor_enable PIN 3 Right_motor_forward PIN 4 Right_motor_reverse PIN 5 Right_motor_enable PIN 6 Move_Forward PIN 7 Move_Backward PIN 8 Move_Left PIN 9 Move_Right PIN 10 ' All motors are off before we start LOW Left_motor_forward LOW Left_motor_reverse LOW Right_motor_forward LOW Right_motor_reverse LOW Left_motor_enable LOW Right_motor_enable '***** Main ******** main: IF (Move_Forward = 1) THEN GOTO forward ELSEIF (Move_Backward = 1) THEN GOTO reverse_motor ELSEIF(Move_Right = 1) THEN GOTO right ELSEIF (Move_Left = 1) THEN GOTO left ELSE GOTO main ENDIF '*********** FORWARD *********** forward: 'turn off motor one LOW Left_motor_forward LOW Left_motor_reverse LOW Left_motor_enable 'turn off motor two LOW Right_motor_forward LOW Right_motor_reverse LOW Right_motor_enable '******************** DO HIGH Left_motor_enable HIGH Right_motor_enable HIGH Left_motor_forward LOW Left_motor_reverse HIGH Right_motor_forward LOW Right_motor_reverse LOOP UNTIL (Move_Forward = 0) PAUSE 500 'run for a 1/2 second and then move on GOTO main '*********** TURN RIGHT *********** right: 'turn off motor one LOW Left_motor_forward LOW Left_motor_reverse LOW Left_motor_enable 'turn off motor two LOW Right_motor_forward LOW Right_motor_reverse LOW Right_motor_enable '****************** DO HIGH Left_motor_enable 'Enable motor 1 HIGH Right_motor_enable 'Enable motor 2 HIGH Left_motor_forward LOW Left_motor_reverse LOW Right_motor_forward HIGH Right_motor_reverse LOOP UNTIL (Move_Right = 0) PAUSE 500 'wait here at this line in the program for 1/2 second GOTO main '*********** TURN LEFT *********** left: 'turn off motor one LOW Left_motor_forward LOW Left_motor_reverse LOW Left_motor_enable 'turn off motor two LOW Right_motor_forward LOW Right_motor_reverse LOW Right_motor_enable '************************ DO HIGH Left_motor_enable HIGH Right_motor_enable LOW Left_motor_forward HIGH Left_motor_reverse LOW Right_motor_forward HIGH Right_motor_reverse LOOP UNTIL (Move_Left = 0) PAUSE 500 GOTO main '*********** REVERSE *********** reverse_motor: 'turn off motor one LOW Left_motor_forward LOW Left_motor_reverse LOW Left_motor_enable 'turn off motor two LOW Right_motor_forward LOW Right_motor_reverse LOW Right_motor_enable '************************** DO HIGH Left_motor_enable 'turn motor 1 on HIGH Right_motor_enable 'turn motor 2 on LOW 1 HIGH 2 LOW 4 HIGH 5 LOOP UNTIL(Move_Backward = 0) PAUSE 500 'wait 1/2 second GOTO main
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
-Where's the code for receiving signals from the receiver?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"The man who smiles when things go wrong has thought of someone to blame it on."
-Lucky[size=-1][/size]