Open tamberg opened 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?
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.
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 ;-)
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