Shop OBEX P1 Docs P2 Docs Learn Events
Must I specify SPI pins as hardwired pins numbers? — Parallax Forums

Must I specify SPI pins as hardwired pins numbers?

When I use a shift out operator, can I not use a variable to specify the pin number?

If not, why not? I always thought that naming pin numbers is good programming practice.

Comments

  • jmgjmg Posts: 15,140
    When I use a shift out operator, can I not use a variable to specify the pin number?

    If not, why not? I always thought that naming pin numbers is good programming practice.

    Depends what you mean.
    In any language, it is usual/desirable to have a common defined name, that is used many times elsewhere in code.

    Mostly, those are actually constants, in that the compilers evaluate and replace at compile time.

    A true variable, allows a run time change, and that is slower, and requires more code.
  • JonnyMacJonnyMac Posts: 8,912
    edited 2018-03-04 22:54
    If not, why not? I always thought that naming pin numbers is good programming practice.
    It is. I have also asked the Blockly team to considered named CONSTANTS for pin numbers, because in a given application most don't change.
  • I meant specifically in Blockly.
  • Ken GraceyKen Gracey Posts: 7,386
    edited 2018-03-05 05:28
    Tom, for some blocks (pulses, servos, audio) you can choose the "other" pin number and insert a variable.

    We are making two improvements to this system for the next release. All blocks appropriate for this addition will have the "other" option and we will also implement the constant definition so it does not use RAM.

    So, it's coming!

    Ken Gracey
  • As Ken mentioned, there is an "other" option on some blocks. It could be added to protocol blocks, too. I'll add an issue for it.
    Thanks!
    Matt
Sign In or Register to comment.