Automaton icon indicating copy to clipboard operation
Automaton copied to clipboard

Posibility to specify pinmode on Atm_button

Open mbariola opened this issue 6 years ago • 10 comments

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

mbariola avatar Jan 02 '19 00:01 mbariola

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. :-)

tinkerspy avatar Jan 02 '19 08:01 tinkerspy

Hi, Actually I'd need the button to be active HIGH... Thanks for pointing that out. Yes I much prefer working on pull-down and high active to save resistors. Maybe an option to configure the active state would be also needed.

I'll have a look at atm_digital, to see if it has the features I need.. Such as debounce. Thanks for the quick answer and good luck with your project!

On Wed, Jan 2, 2019, 09:08 Tinkerspy <[email protected] wrote:

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. :-)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tinkerspy/Automaton/issues/60#issuecomment-450805025, or mute the thread https://github.com/notifications/unsubscribe-auth/AEqp31diV9xFbmZyq033rgAuhcCDOPo5ks5u_GjygaJpZM4ZmFiB .

mbariola avatar Jan 02 '19 08:01 mbariola

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

tinkerspy avatar Jan 02 '19 08:01 tinkerspy

Seems good then, I'll try that way. Just curious... Saved 5 resistors, anything to do with a wearable? 😉

On Wed, Jan 2, 2019, 09:16 Tinkerspy <[email protected] wrote:

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

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tinkerspy/Automaton/issues/60#issuecomment-450806112, or mute the thread https://github.com/notifications/unsubscribe-auth/AEqp35xjJebAsU3rRQWJo5XArxfOm0-eks5u_GrggaJpZM4ZmFiB .

mbariola avatar Jan 02 '19 11:01 mbariola

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

tinkerspy avatar Jan 02 '19 12:01 tinkerspy

Nice! I'd love to see its tutorial for the automaton part 😉

On Wed, Jan 2, 2019, 13:49 Tinkerspy <[email protected] wrote:

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

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tinkerspy/Automaton/issues/60#issuecomment-450855553, or mute the thread https://github.com/notifications/unsubscribe-auth/AEqp36VP3jlzuHOc8nhFrh-VRtefgkokks5u_Kr0gaJpZM4ZmFiB .

mbariola avatar Jan 02 '19 12:01 mbariola

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.

matthijskooijman avatar Jan 12 '19 23:01 matthijskooijman

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

tinkerspy avatar Jan 13 '19 19:01 tinkerspy

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 :-)

mbariola avatar Jan 25 '19 13:01 mbariola

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

sjernigan avatar Feb 06 '24 16:02 sjernigan