Shop OBEX P1 Docs P2 Docs Learn Events
line follower & ping sensor — Parallax Forums

line follower & ping sensor

KayduhKayduh Posts: 9
edited 2013-08-13 23:50 in BASIC Stamp
So i have my line follower code all worked out, Im trying to add the ping sensor for collision detection. In my code i have Im not sure where to put the code to check the distance for the sensor and to send the motor stop pulses. On that note, im not even sure if I wrote the code for checking and the if statement to stop the motors correctly. Anyways, I attached a copy of the code, can anyone look it over and tell me what im doing wrong.

I think its because while the program is looping its looping from "select qtis" untill "endselect" im thinking i need to add the code to check the ping, and also the if statement inside that main loop, but i have no idea where to put it.
DO
  GOSUB Check_Qtis


 ' PULSOUT Ping_Pin, 5              ' Send short pulse to Ping
 ' PULSIN Ping_Pin, 1, time         ' Wait for echo
 ' inDistance = inConstant ** time  ' Convert to inches


 '   IF (inDistance < 6) THEN
 '   PAUSE 5
 '   PULSOUT HB25, 750
 '   PAUSE 1
 '   PULSOUT HB25, 750
 '   ENDIF


  SELECT qtis


    CASE %1000
      PAUSE 5
      PULSOUT HB25, 750
      PAUSE 1
      PULSOUT HB25, 695


    CASE %1100
     PAUSE 5
      PULSOUT HB25, 750
      PAUSE 1
      PULSOUT HB25, 695


    CASE %1110
      PULSOUT HB25, 625
      PAUSE 1
      PULSOUT HB25, 625


    CASE %0100
     PAUSE 5
      PULSOUT HB25, 750
      PAUSE 1
      PULSOUT HB25, 695


    CASE %0110
     PAUSE 5
      PULSOUT HB25, 805
      PAUSE 1
      PULSOUT HB25, 685


    CASE %0010
     PAUSE 5
      PULSOUT HB25, 805
      PAUSE 1
      PULSOUT HB25, 750


    CASE %0001
     PAUSE 5
      PULSOUT HB25, 805
      PAUSE 1
      PULSOUT HB25, 750


    CASE %0011
     PAUSE 5
      PULSOUT HB25, 805
      PAUSE 1
      PULSOUT HB25, 750


    CASE %0111                           
      PULSOUT HB25, 875
      PAUSE 1
      PULSOUT HB25, 875


    CASE ELSE


  ENDSELECT
  LOOP


Check_Qtis:


  DIRB = %1111
  PAUSE 0
  DIRB = %0000
  PAUSE 0
  qtis = INB


  RETURN
Sign In or Register to comment.