EduIntro icon indicating copy to clipboard operation
EduIntro copied to clipboard

Button.pressed()?

Open tamberg opened this issue 7 years ago • 3 comments

Hi,

Would it make sense to introduce something like button.pressed() instead of readSwitch() ? E.g. in https://github.com/arduino/EduIntro/blob/master/examples/by_topic/Button/Button.ino#L29

if (button.readSwitch() == LOW) { led.on(); } else { led.off(); }

if (button.pressed()) { led.on(); } else { led.off(); }

Or isPressed(), as in isPWM()

Kind regards, Thomas

tamberg avatar Aug 15 '18 13:08 tamberg

I was thinking about it. I went for this example because I wanted to make a case for a complex interaction that is hard to make with code closer to the basic Arduino API. I think one way around this would be adding a couple of commented lines letting users try one or the other just to experience the difference.

What do you think?

dcuartielles avatar Aug 15 '18 19:08 dcuartielles

Oh, I did not realise that pressed() / released() are already part of the library. To demonstrate simplicity of EduIntro, if (button.pressed()) { led.on(); } else { led.off(); } might be better suited.

tamberg avatar Aug 15 '18 22:08 tamberg

I will prepare a revised version of the library with two examples ... button will be as you say and I will make another one including the code we have now.

It will not be today though ;-)

dcuartielles avatar Aug 16 '18 07:08 dcuartielles