Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Posibility to specify pinmode on Atm_button #60

Open
mbariola opened this issue Jan 2, 2019 · 10 comments
Open

Posibility to specify pinmode on Atm_button #60

mbariola opened this issue Jan 2, 2019 · 10 comments

Comments

@mbariola
Copy link

mbariola commented Jan 2, 2019

Hi,

I'm currently evaluating your framework to try it out on a Cortex M0 and an ESP32, both of which have INPUT_PULLDOWN capabilities (which is more suitable to my project).

I'll quickly hack it locally as my time is limited, but maybe you would consider extending Atm_button to provide an extra parameter for the PINMODE, for a minor update?

Best

@tinkerspy
Copy link
Owner

Hi Best,

I could fairly easily add an input_mode argument to the begin() method, if that works for you. But Atm_button would still be 'active LOW'. Is that useful?

You could also use Atm_digital instead, that class can handle active high inputs. Just call pinMode after initialization:

Atm_digital button;

button.begin( 3, 20, true, true );
    .onChange( led, led.EVT_TOGGLE ); 

pinMode( 3, INPUT_PULLDOWN );

BTW: You just saved me 5 pulldown resistors on my current Teensy 3.5 project. :-)

@mbariola
Copy link
Author

mbariola commented Jan 2, 2019 via email

@tinkerspy
Copy link
Owner

It's got debounce, just the fancier stuff like longpress, repeat & autopress are missing.

@mbariola
Copy link
Author

mbariola commented Jan 2, 2019 via email

@tinkerspy
Copy link
Owner

No, a pinball machine. Not very wearable ;-)

@mbariola
Copy link
Author

mbariola commented Jan 2, 2019 via email

@matthijskooijman
Copy link

I just realized I'm also in need of this (I have a button that must be active-high since it also toggles something else), but I also need longpress, so I can't use digital. I guess you could add begin() parameters for both pinmode and active-low/active-high?

In general, adding more arguments to begin() doesn't scale very well. Ideally, you would want something like Python's keyword-arguments (so all arguments are optional and you can pass any of them without having to specify all of the previous ones) but that's tricky in C++ (there are some Boost-libraries that can do something like this, but the underlying code is very complex). One thing that could work is to add chainable methods for setting all kinds of these options (e.g. button.pin(13).pinMode(INPUT_PULLUP).active(HIGH).begin()) where you set individual settings with methods rather than (or in addition to) begin() parameters. This might fit Automaton well in terms of syntax. One downside is that all settings must be stored inside the object then (whereas parameters to begin() can be used inside begin() without being forced to store them.

@tinkerspy
Copy link
Owner

tinkerspy commented Jan 13, 2019

OK, that sounds like a plan. I made a branch with the new pinMode() & active() methods. Note that they must be called after begin(). Would you mind checking it out and testing it?

  button.begin( 13 )
    .pinMode( INPUT_PULLDOWN )
    .active( LOW )
    .onPress( led, led.EVT_ON );

The branch is here

@mbariola
Copy link
Author

Hey @tinkerspy !
Sorry if it took me a lot to answer, I will try the new branch with a brand new prototype starting this monday, and will let you know. Thanks for taking the time :-)

@sjernigan
Copy link

I added this in fork https://github.com/sjernigan/Automaton and put in a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants