Shop OBEX P1 Docs P2 Docs Learn Events
Help with Spin code — Parallax Forums

Help with Spin code

jimejime Posts: 4
edited 2015-03-10 22:28 in Propeller 1
I am new at programming with Spin. I am looking at K W Agyeman's Half Duplex Communication Engine from the OBEX. What does the following code do?

if(!RXPin)
dira[RXPin] := outa[RXPin] := 0

Comments

  • JonnyMacJonnyMac Posts: 9,105
    edited 2015-03-10 16:44
    When you start that object you may chose not to use an RX pin -- when that is the case you must use -1 as the pin #. Using ! with -1 returns 0 (false), hence the indented line would be skipped. I tend to wear may "Captain Obvious" cosplay gear when programming, so I would have written that fragement this way:
    if (rxpin => 0)
        dira[rxpin] := 0
        outa[rxpin] := 0
    


    ...which sets the pin to input state (first line) and clears the output bit (second line) for that pin.

    No, I don't actually have a Captain Obvious costume. But I know a lot of pro cosplayers and I work in Hollywood -- I could have one any time I want! It would of course be Propeller powered.
  • jimejime Posts: 4
    edited 2015-03-10 17:48
    Thanks JonnyMac

    Now the comments in the EngineStart method make sense. As a beginner, I prefer your coding style.

    Jime
  • JonnyMacJonnyMac Posts: 9,105
    edited 2015-03-10 22:28
    Glad to help. FWIW, some programmers will write in that compressed manner thinking it save space. In this case, it does't. I compiled a test program that consisted of just a main method, a local variable, and the test code. In both cases the program compiles to 24 longs.

    A program serves two purposes: 1) to instruct the controller, and 2) to inform other programmers. We can handle #2 with comments, but I prefer to write obvious code the documents itself.
Sign In or Register to comment.