Added pinMode setting to attach #21

Merged
septillion-git merged 2 commits from master into master 2015-09-08 20:55:15 +03:00
septillion-git commented 2015-09-08 13:33:05 +03:00 (Migrated from github.com)

This way you only need to call attach(pin, mode) and it will also set the pinMode. Reduces the setup of a input to one line. To maintain backwards compatibility attach(pin) is still there, it's just an extension.

This way you only need to call attach(pin, mode) and it will also set the pinMode. Reduces the setup of a input to one line. To maintain backwards compatibility attach(pin) is still there, it's just an extension.
thomasfredericks commented 2015-09-08 18:08:20 +03:00 (Migrated from github.com)

Hi, I prefer to keep these separate as the INPUT_PULLUP mode is relatively new and it breaks compatibility with Wiring.

Hi, I prefer to keep these separate as the INPUT_PULLUP mode is relatively new and it breaks compatibility with Wiring.
thomasfredericks commented 2015-09-08 18:10:26 +03:00 (Migrated from github.com)

There could also be a case when the mode could be output (I don't have an actual example, but it could be possible with 1 wire Ping sensors).

There could also be a case when the mode could be output (I don't have an actual example, but it could be possible with 1 wire Ping sensors).
septillion-git commented 2015-09-08 18:48:07 +03:00 (Migrated from github.com)

Hi,
This implementation does not break the old one. So if you prefer to use
pinMode(pin, INPUT);
test.attach(pin);
That's still possible.

Also, it's 1 to 1 to pinMode. So calling
test.attach(pin, OUTPUT);
is fully possible. Also changing it back and forth between input and output afterwards is no problem.

And because it's 1 to 1 with pinMode it does not break with Wiring. INPUT_PULLUP isn't defined in Wiring so you can't call it. But you can call
test.attach(pin, INPUT);
digitalWrite(pin, HIGH); //enable pullups in wiring
And it still saves you from calling pinMode()

Like I said, everything that's possible now is still possible then. Only for simple "just input" cases you can simplify the code with
test.attach(pin, INPUT_PULLUP);
It makes it possible to fully setup a button with debounce an pullup in just 1 line of code.

Hi, This implementation does not break the old one. So if you prefer to use pinMode(pin, INPUT); test.attach(pin); That's still possible. Also, it's 1 to 1 to pinMode. So calling test.attach(pin, OUTPUT); is fully possible. Also changing it back and forth between input and output afterwards is no problem. And because it's 1 to 1 with pinMode it does not break with Wiring. INPUT_PULLUP isn't defined in Wiring so you can't call it. But you can call test.attach(pin, INPUT); digitalWrite(pin, HIGH); //enable pullups in wiring And it still saves you from calling pinMode() Like I said, everything that's possible now is still possible then. Only for simple "just input" cases you can simplify the code with test.attach(pin, INPUT_PULLUP); It makes it possible to fully setup a button with debounce an pullup in just 1 line of code.
thomasfredericks commented 2015-09-08 19:01:00 +03:00 (Migrated from github.com)

This implementation does not break the old one.

I understand that.

Also, it's 1 to 1 to pinMode. So calling [...]

First, your code does not take into account "test.attach(pin, OUTPUT);", it will be set as an INPUT. Next, if Arduino adds more pin modes, that code will always need to be updated.

INPUT_PULLUP isn't defined in Wiring so you can't call it. But you can call [...]

Since it is not defined it will not compile hence break compatibility with Wiring.

Overall, the cost of maintenance is too much to implement this feature. Also, since Arduino is aimed at beginners, it is always best to make the simplest functions possible.

> This implementation does not break the old one. I understand that. > Also, it's 1 to 1 to pinMode. So calling [...] First, your code does not take into account "test.attach(pin, OUTPUT);", it will be set as an INPUT. Next, if Arduino adds more pin modes, that code will always need to be updated. > INPUT_PULLUP isn't defined in Wiring so you can't call it. But you can call [...] Since it is not defined it will not compile hence break compatibility with Wiring. Overall, the cost of maintenance is too much to implement this feature. Also, since Arduino is aimed at beginners, it is always best to make the simplest functions possible.
septillion-git commented 2015-09-08 19:57:01 +03:00 (Migrated from github.com)

Your looking at the wrong commit ;) Latest commit is the lowest. I indeed first did a test with only allowing INPUT modes but realized that's dumb. (But I already made a commit, bit dumb but I'm still getting used to GitHub...)

Now it's just 1 to 1 pinMode. So

  1. OUTPUT does work.
  2. You don't need to update it because if pinMode expands to more modes you can just use them
  3. aka, no maintenance
  4. INPUT_PULLUP isn't in there so it will compile just fine

And I agree to make simple functions. That's why I think it's good to include pinMode into the library so people don't have to call it next to the library. One line of code sets up everything for a button.

Your looking at the wrong commit ;) Latest commit is the lowest. I indeed first did a test with only allowing INPUT modes but realized that's dumb. (But I already made a commit, bit dumb but I'm still getting used to GitHub...) Now it's just 1 to 1 pinMode. So 1) OUTPUT does work. 2) You don't need to update it because if pinMode expands to more modes you can just use them 3) aka, **no** maintenance 4) INPUT_PULLUP isn't in there so it will compile just fine And I agree to make simple functions. That's why I think it's good to include pinMode into the library so people don't have to call it next to the library. One line of code sets up everything for a button.
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Max/thomasfredericks_Bounce2#21