Shop OBEX P1 Docs P2 Docs Learn Events
time-out code for waitpeq — Parallax Forums

time-out code for waitpeq

Is there a way to time out and restart some code from the beginning after a certain period of time, like 15 seconds if a waitpeq is not is not progressed past?
repeat
 
 
      
    if INA[7]==1
                                      
         
         lcd.str(string(12))                 
         waitcnt(clkfreq/100+cnt)  
         lcd.str(string("deposit 2",17,13))
         waitcnt(clkfreq/100+cnt)   
         lcd.str(string("quarters."))
         waitcnt(clkfreq/100+cnt)                             'initial call for audio triggered by pir, ina[7]  
           dac.playWAVFile(string("whistle.wav"))   
           
           waitpeq(%100000000000000000000, |< 20, 0) 'Wait for Pin 20 to go high
           waitpeq(%000000000000000000000, |< 20, 0) 'Then wait for Pin 20 to go low

Comments

  • JonnyMacJonnyMac Posts: 8,927
    edited 2018-03-03 07:50
    There is no time-out available for waitXXX instructions -- but you could do something like this:
    pub wait4pin(pin, state, toms) | t
    
    '' Wait for pin to match state for no longer that toms milliseconds
    '' -- returns true if pin matches state before timeout
    '' -- pin is 0..27
    '' -- state is 0..1
    '' -- toms is milliseconds (positive)
    
      t := cnt
      repeat toms
        if (ina[pin] == state)
          return true
        waitcnt(t += clkfreq/1000)
    
  • Thanks Jon, got it working.
Sign In or Register to comment.