Shop OBEX P1 Docs P2 Docs Learn Events
help with my code basic stamp — Parallax Forums

help with my code basic stamp

hi, i'm oscar
I am an apprentice in programming, to see if they can help me. the idea is a robot, it moves with servo motors, and detects obstacles with an SRF05, it is a basic stamp 2sx, that's why the pulsout so high. my problem is that the code is not debugged to choose between two digits and make the code shorter in the detection of obstacles.
IF Range = 30 THEN ' Si la medida es 30, 29, 28 va a la rutina obstaculo
GOSUB atras '
ELSE '
PAUSE 100 '
ENDIF '
IF Range = 29 THEN '
GOSUB atras '
ELSE '
PAUSE 100 '
ENDIF '
IF Range = 28 THEN '
GOSUB atras '
ELSE '
PAUSE 100 '
ENDIF ' Si la medida es 30, 29, 28 va a la rutina obstaculo
the other problem is that when the program is executed, the robot advances by beating. the plate is powered by 9 v and 300 milliamps, feeds the servo motors and the basic stamp together. where is the problem , in the stream. or breaks
complet code:
' {$STAMP BS2sx}
' {$PBASIC 2.5}

SRF05 PIN 11 ' PIN 11 TRIG
SRF05x PIN 12 ' PIN 12 ECHO

SRF052 PIN 13 ' PIN 13 TRIG
SRF052x PIN 14 ' PIN 14 ECHO

Range VAR Word

inicio:
DO
PULSOUT 14, 1000 ' Avanza
PULSOUT 15, 2500
PAUSE 20

SRF05 = 0 ' Inicia el pin 11 en estado bajo
PULSOUT SRF05, 5 ' envia al PIN Trigger un pulso de 10uS (5 x 2uS)
PULSIN SRF05x, 1, Range ' mide el tienpo del PIN Echo pin 12
Range = Range/29 ' convierte la medida a cm (Range/29)
PAUSE 100 ' pausa de 50'

DEBUG CR, "Distancia = ", DEC4 Range, " cm" ' Muestra la distancia

IF Range = 30 THEN ' Si la medida es 30, 29, 28 va a la rutina obstaculo
GOSUB atras '
ELSE '
PAUSE 100 '
ENDIF '
IF Range = 29 THEN '
GOSUB atras '
ELSE '
PAUSE 100 '
ENDIF '
IF Range = 28 THEN '
GOSUB atras '
ELSE '
PAUSE 100 '
ENDIF ' Si la medida es 30, 29, 28 va a la rutina obstaculo

LOOP

GOTO inicio
atras:
FOR counter =1 TO 100
PULSOUT 14, 2500
PULSOUT 15, 1000
PAUSE 20
NEXT
adelante:
FOR counter =1 TO 100
PULSOUT 14, 1000
PULSOUT 15, 2500
PAUSE 20
NEXT
derecha:
FOR counter =1 TO 100
PULSOUT 14, 1000
PULSOUT 15, 1000
PAUSE 20
NEXT
izquierda:
FOR counter =1 TO 100
PULSOUT 14, 2500
PULSOUT 15, 2500
PAUSE 20
NEXT
END
GOTO inicio

thanks

Comments

  • The code needs better formatting, put '{STAMP BS2sx} and'{$PBASIC 2.5} at the top of the program, after that your pin assignments, followed by your variables Range VAR word. delete or commet out " the other problem is" sentence. I assigned counter as, counter VAR word. My spanish isn't that great.

  • thanks, I will try it and publish the results.

Sign In or Register to comment.