Shop OBEX P1 Docs P2 Docs Learn Events
Digital I-O Board in Serial Mode – Byte back to individual Bit — Parallax Forums

Digital I-O Board in Serial Mode – Byte back to individual Bit

T-townT-town Posts: 17
edited 2014-05-30 01:20 in General Discussion
I've been messing around with my Parallax Digital I-O board model 27113 http://www.parallax.com/product/27113 using the serial interface. I am using the Parallax sample code they provided. Can someone give me an example of how to take the "optos" byte sent from the inputs (in the sample code) and convert that into 8 individual bits that represent each input? Ditto for the "index" byte to the outputs. I’ve been able to read a single input and force an output but only using the octal number (If optos = 1 then….2, 4, 8….). I’m thinking there has to be an easy way to convert the 255 combinations back to 8 bits I can use in code. Keeping the explanation simple would be appreciated. I’m pretty new to this. Thanks as always. Joe

Comments

  • SapphireSapphire Posts: 496
    edited 2014-05-29 20:24
    You could use the .BIT modifier to get the individual bits of the two bytes:

    optos.BIT0 ' this is the first bit
    optos.BIT1 ' this is the second bit
    optos.BIT7 ' this is the last bit

    Same goes for index.
    IF optos.BIT2 = 1 THEN     ' do something if bit 2 is on
    
    index.BIT4 = 0   ' set output bit 4 off
    index.BIT7 = 1   ' set output bit 7 on
    
  • T-townT-town Posts: 17
    edited 2014-05-30 01:20
    Perfect, thank you. I declared variables for each of the input and outputs using the .bit. Working great; thanks for the nudge in the right direction!
Sign In or Register to comment.