Shop OBEX P1 Docs P2 Docs Learn Events
Need help with this Loop. Its not doing what its supposed to — Parallax Forums

Need help with this Loop. Its not doing what its supposed to

StatzStatz Posts: 28
edited 2008-11-13 14:02 in BASIC Stamp
' {$STAMP BS2}
' {$PBASIC 2.5}
'{1 to 6 with a pause 20 is equivalant to 1 inch)
irDetectLeft VAR Bit
pulseCount VAR Byte
pulseLeft VAR Word
pulseRight VAR Word
loopCount VAR Byte
irDetectMiddle VAR Bit
hit VAR Nib
finish CON 4            'Just a constant of if a square is made
turn VAR Nib            'Will increase if a full corner turn is predicted
'measure VAR Byte      'Variable for distance in inches

DO
  FREQOUT 8, 1, 41500
  irDetectLeft = IN10
  FREQOUT 2, 1, 41500
  irDetectMiddle = IN0
  IF (irDetectMiddle = 0)  THEN
  DO
    PULSOUT 13, 850
    PULSOUT 12, 800                     
  LOOP UNTIL (irDetectLeft = 0)
 
=====more code=======


Basically, it stays in an infinite loop. not sure why at all. Its just a boe-bot with 2 Irs.

Post Edited (Statz) : 11/13/2008 4:39:56 AM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-13 04:50
    It stays in the DO / LOOP because irDetectLeft doesn't change. You need to move the FREQOUT and reading of irDetectLeft into the loop.
    You may want to rethink the whole thing (where the IR detection fits into the movement logic).
    You really didn't say what you're trying to accomplish with the program. That helps when you ask a question.
  • StatzStatz Posts: 28
    edited 2008-11-13 04:58
    Thanks mike, you seem to always be helping me out

    That makes sooooooooooooooooooooo much sense
    lol! how simple. I kept revising my code. Thanks, that basically solved the whole problem burger.gif
  • GICU812GICU812 Posts: 289
    edited 2008-11-13 08:44
    Tell me about it, he takes all the fun out of this, no one else ever gets to answer a question [noparse]:([/noparse]

    Joking of course,
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-11-13 13:54
    GICU812 said...
    Tell me about it, he takes all the fun out of this, no one else ever gets to answer a question [noparse]:([/noparse]

    Joking of course,
    Aw, c'mon.· Lots of people answer questions.· The difference is, 80% of the answers are wrong, but Mike's answers are right. turn.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-11-13 14:02
    Also, when you're controlling a servo, you MUST have a "pause 20" to give the servo a 20 millisecond delay between servo refresh pulses.
Sign In or Register to comment.