\ SEEKER.TXT - THE SEEKER APPLICATION
\
\ REQUIRES: SCAN1.TXT SCAN2.TXT BUMPER.TXT BUTTONAPI.TXT

: SEEKER

  RCX_INIT
  SENSOR_INIT

  0 SENSOR_BOOL_MAKE
  1 SENSOR_LIGHT_MAKE

  BEGIN
    BUTTON_SCAN BUTTON_RUN?
  UNTIL

  SCAN_FOR_PEAK

  BEGIN
    0    \ Assume we can't find the peak
         \ Scan back and forth to look for the peak

    6 1 DO
      I 1 AND I 6 * FIND_PEAK
      IF DROP 1 LEAVE
      THEN
    LOOP

    \ Now check the bumper, if we've hit something or
    \ we can't find the peak, indicate false

    CHECK_BUMPER
    IF   DROP 0
    THEN    

    \ If we find the peak move forward, otherwise scan
    \ around and look for a new peak

    IF   BOT_FORWARD
         12 0 timer_SET
         BEGIN
           BUTTON_SCAN
           0 timer_GET 0=
         UNTIL
         BOT_STOP
    ELSE SCAN_FOR_PEAK
    THEN

    \ Keep doing this until the RUN button is pressed

    BUTTON_RUN?
  UNTIL ;
