arduino / EduIntro

Arduino library aimed at making super-fast introductory workshops to Arduino. Based on the idea of having components as objects in the code.
GNU General Public License v3.0
37 stars 14 forks source link

Button.pressed()? #2

Open tamberg opened 6 years ago

tamberg commented 6 years ago

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

dcuartielles commented 6 years ago

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?

tamberg commented 6 years ago

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.

dcuartielles commented 6 years ago

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