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

  • 2 Comments sorted by Date Added Votes
  • JonnyMacJonnyMac Posts: 6,114
    edited March 3 Vote Up0Vote Down
    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)
    
    Jon McPhalen
    Hollywood, CA
    It's Jon or JonnyMac -- please do not call me Jonny.
  • Thanks Jon, got it working.
Sign In or Register to comment.