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.
Re-inventing the wheel is not a waste of time if, when you are done, you understand why it is round.

Comments

  • 5 Comments sorted by Date Added Votes
  • jmgjmg Posts: 12,618
    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: 6,114
    edited March 4 Vote Up0Vote Down
    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.
    Jon McPhalen
    Hollywood, CA
    It's Jon or JonnyMac -- please do not call me Jonny.
  • I meant specifically in Blockly.
    Re-inventing the wheel is not a waste of time if, when you are done, you understand why it is round.
  • Ken GraceyKen Gracey Posts: 6,359
    edited March 5 Vote Up0Vote Down
    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
    Matthew Matz
    STEM/Robotics Educator
    Parallax Inc.
Sign In or Register to comment.