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: 14,495
    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: 7,008
    edited 2018-03-04 - 22:54:33
    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: 6,893
    edited 2018-03-05 - 05:28:09
    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.