-
Notifications
You must be signed in to change notification settings - Fork 39
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
Provide an event based API for EV3 buttons #90
Comments
Done for C++ and exposed in Python. For now each button should be handled individually: def say_hello(pressed): if pressed: print('hello')
button.enter.onclick( say_hello )
while True: button.enter.process() What I don't like about this is the processing part. I think I would prefer a single Of course, it may be easily done on the user side of the code as well. |
This is a convenience method that simply calls process() for each of the EV3 buttons. See #90.
I've added a static |
|
Something like this should work: // Set a functor (here created as a lambda function) as the button event handler:
ev3dev::button::enter.onclick = [](bool state) {
std::cout << state ? "pressed" : "not pressed" << std::endl;
};
// Do event processing in a loop. Whenever the enter button changes state,
// the onclick functor is called with the appropriate argument:
while (!ev3dev::button::back.pressed())
ev3dev::button::enter.process(); |
Similar to how it is implemented in the
remote_control
class.The text was updated successfully, but these errors were encountered: