Shop OBEX P1 Docs P2 Docs Learn Events
Another CASE question — Parallax Forums

Another CASE question

eagletalontimeagletalontim Posts: 1,399
edited 2013-12-05 21:51 in Propeller 1
Is there an "AND" expression with CASE or can I simply use AND in the expression? I am reading the input of a 165 and need to do specific things based on the feedback of the 165 pin states. If 2 specific pins are HIGH on the 165, I need it to run one specific code.
    repeat i from 0 to 7
      xInputs := ina[Lever_DATA]
      if xInputs == 1
        case i
          1: selected := 1
          2: selected := 2
          3: selected := 3
          4: selected := 4         ' only set to 4 if just this one pin is active
          5: selected := 5
          6: selected := 6
          4 AND 7: selected := 7  ' set selected to 7 if both pin 4 and 7 are active
      outa[Lever_CLK] := 1
      outa[Lever_CLK] := 0
    
    process_pin_selection(selected)

Comments

  • eagletalontimeagletalontim Posts: 1,399
    edited 2013-12-05 21:47
    Just thought of something... My logic will not work that way as "i" will never be 4 and 7 at the same time..... time to rethink. Need to sleep on this one :p
  • JonnyMacJonnyMac Posts: 9,107
    edited 2013-12-05 21:51
    Probably better to read them all at once into a single byte, and then process them together:
    switches := read_165  
      case switches
         %_0000_0001:
          ' switch 1 code
    
    
         %_0000_0010:
          ' switch 2 code
    
    
         %_0000_0100:
          ' switch 3 code
    
    
         %_0000_1000:
          ' switch 4 (only) code
    
    
         %_0001_0000:
          ' switch 5 code
    
    
         %_0010_0000:
          ' switch 6 code
    
    
         %_0100_1000:
          ' switch 7 and 4 code
       
        otherwise:
          ' unexpected inputs code
    


    For reasons I don't understand the forums editor doesn't like the binary indicator (percent sign) when a digit follows it -- hence the underscore (which you need to remove in the Propeller Tool).
Sign In or Register to comment.