Shop OBEX P1 Docs P2 Docs Learn Events
trying to use "or" — Parallax Forums

trying to use "or"

mikeamikea Posts: 283
edited 2012-04-25 19:31 in Propeller 1
I have 3 sensors and dont want them to get "stuck" in a repeat loop if the trigger has moved into the zone of another sensor. i want the code to say ...repeat until motion is sensed in zone 2 or zone 3 (if its currently in zone 1) so its position is updated. I think im not using the correct "or" operator. Ive tried |,or,^.Any help would be appreciated.-mike

if ina[1]==1

repeat until ina[2]==1 or ina[3]==1
outa[pin]~~

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2012-04-25 19:14
    There is nothing wrong as such with your usage of boolean or. What are you expecting to happen and what does in fact happen? For debugging purposes you could display (LED/serial) the state of ina[2..3] inside the loop. The example below is based on your fragment. It waits for an event in zone 1 then idles in a loop waiting for events in either zone 2 or 3 which will be provided after 5 seconds. Then it simply indicates that it left the loop (LEDs on pins 16..23, demoboard).
    VAR
      long  stack[32]
      
    PUB null
    
      dira[1..3]~~
      dira[16..23]~~
      cognew(buttons, @stack{0})
    
      repeat
        if ina[1]
          !outa[16]                                         ' in zone 1
          repeat until ina[2][COLOR="#D3D3D3"]{== 1}[/COLOR]or ina[3][COLOR="#D3D3D3"]{== 1}[/COLOR]
            !outa[17]                                       ' waiting
            waitcnt(clkfreq/4 + cnt)
          !outa[23]                                         ' event in 2/3
          
    PRI buttons
    
      dira[1..3]~~
      waitcnt(clkfreq + cnt)
      outa[1] := 1                                          ' zone 1 event
      waitcnt(clkfreq*5 + cnt)
      outa[2] := 1                                          ' zone 2 event
    
      waitpne(0, 0, 0)                                      ' keep "buttons" alive
    
  • mikeamikea Posts: 283
    edited 2012-04-25 19:31
    kuroneko thanks, i see my problem now. i didn't apply the "or"s to the other 2 zones.-mike
Sign In or Register to comment.