The BounceButton class adds the setInvert() function to the Bounce class, which can be used to invert the new pressed() and released() functions. read() is also adjusted so that you can use setInvert() with it. This class is intended for inverting a button when using INPUT_PULLUP.
The BounceButton class adds the setInvert() function to the Bounce class, which can be used to invert the new pressed() and released() functions. read() is also adjusted so that you can use setInvert() with it. This class is intended for inverting a button when using INPUT_PULLUP.
This comment was generated by todo based on a todo comment in 7e1cb95a9d in #61. cc @NoobTracker.
## Make Bounce2 more abstract. Split it from the hardware layer.
Remove deboucing code from Bounce2 and make a new Debounce class from that code. Bounce2 should extend Debounce.
---
https://github.com/thomasfredericks/Bounce2/blob/7e1cb95a9d289fd178b35f43ac9dd7a3b6ad1a5a/src/Bounce2.h#L30-L35
---
###### This comment was generated by [todo](https://todo.jasonet.co) based on a `todo` comment in 7e1cb95a9d289fd178b35f43ac9dd7a3b6ad1a5a in #61. cc @NoobTracker.
I made a branch ( https://github.com/thomasfredericks/Bounce2/tree/Button ) with the basic idea behind your merge request. Please check the buttonClass example. I did not test it yet. I included the class directly into Bounce2.h
Hi @NoobTracker,
I made a branch ( https://github.com/thomasfredericks/Bounce2/tree/Button ) with the basic idea behind your merge request. Please check the buttonClass example. I did not test it yet. I included the class directly into Bounce2.h
Hi,
the idea with setPressedState () is really good, it is more understandable than setInvert (). The program should work. With stateForPressed, however, the default value is 0, which immediately activates the inversion. That should be changed. I would also return !(getStateFlag(DEBOUNCED_STATE) ^ stateForPressed) && getStateFlag(CHANGED_STATE); use for pressed rather than the current program and maybe outsource the functions to the .cpp file. But that's your decision. In any case, thank you for taking care of the program.
Hi,
the idea with setPressedState () is really good, it is more understandable than setInvert (). The program should work. With stateForPressed, however, the default value is 0, which immediately activates the inversion. That should be changed. I would also `return !(getStateFlag(DEBOUNCED_STATE) ^ stateForPressed) && getStateFlag(CHANGED_STATE);` use for pressed rather than the current program and maybe outsource the functions to the .cpp file. But that's your decision. In any case, thank you for taking care of the program.
Oh, and the example doesn't work because you only switch on the LED if the button was pressed exactly during the last update. Then it goes out again. You would have to make
if ( buttonA.pressed() || buttonB.pressed() ) {
digitalWrite(LED_PIN, HIGH );
}
else {
digitalWrite(LED_PIN, LOW );
}
if ( buttonA.pressed() || buttonB.pressed() ) {
digitalWrite(LED_PIN, HIGH );
}
if ( buttonA.released() || buttonB.released() ) {
digitalWrite(LED_PIN, LOW );
}
You could also make #define LED_PIN 13#define LED_PIN LED_BUILTIN.
Oh, and the example doesn't work because you only switch on the LED if the button was pressed exactly during the last update. Then it goes out again. You would have to make
```
if ( buttonA.pressed() || buttonB.pressed() ) {
digitalWrite(LED_PIN, HIGH );
}
else {
digitalWrite(LED_PIN, LOW );
}
```
```
if ( buttonA.pressed() || buttonB.pressed() ) {
digitalWrite(LED_PIN, HIGH );
}
if ( buttonA.released() || buttonB.released() ) {
digitalWrite(LED_PIN, LOW );
}
```
You could also make `#define LED_PIN 13` `#define LED_PIN LED_BUILTIN`.
Wow, thanks for the error checking. I really messed up ;) I will correct it.
I prefer not to create additional header files to reduce potential conflicts with other libraries. Although they could be hidden in a subfolder inside «src».
Wow, thanks for the error checking. I really messed up ;) I will correct it.
I prefer not to create additional header files to reduce potential conflicts with other libraries. Although they could be hidden in a subfolder inside «src».
"setPressedState" is much clearer. I have a class in my current project that's very similar 😉 . I think you can re-use the state attribute to avoid increasing memory usage. Would it be possible to close this PR and open a new one for your "Button" branch?
"setPressedState" is much clearer. I have a class in my current project that's very similar 😉 . I think you can re-use the state attribute to avoid increasing memory usage. Would it be possible to close this PR and open a new one for your "Button" branch?
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
The BounceButton class adds the setInvert() function to the Bounce class, which can be used to invert the new pressed() and released() functions. read() is also adjusted so that you can use setInvert() with it. This class is intended for inverting a button when using INPUT_PULLUP.
Make Bounce2 more abstract. Split it from the hardware layer.
Remove deboucing code from Bounce2 and make a new Debounce class from that code. Bounce2 should extend Debounce.
https://github.com/thomasfredericks/Bounce2/blob/7e1cb95a9d289fd178b35f43ac9dd7a3b6ad1a5a/src/Bounce2.h#L30-L35
This comment was generated by todo based on a
todocomment in7e1cb95a9din #61. cc @NoobTracker.Hi @NoobTracker,
I made a branch ( https://github.com/thomasfredericks/Bounce2/tree/Button ) with the basic idea behind your merge request. Please check the buttonClass example. I did not test it yet. I included the class directly into Bounce2.h
Hi,
the idea with setPressedState () is really good, it is more understandable than setInvert (). The program should work. With stateForPressed, however, the default value is 0, which immediately activates the inversion. That should be changed. I would also
return !(getStateFlag(DEBOUNCED_STATE) ^ stateForPressed) && getStateFlag(CHANGED_STATE);use for pressed rather than the current program and maybe outsource the functions to the .cpp file. But that's your decision. In any case, thank you for taking care of the program.Oh, and the example doesn't work because you only switch on the LED if the button was pressed exactly during the last update. Then it goes out again. You would have to make
You could also make
#define LED_PIN 13#define LED_PIN LED_BUILTIN.Wow, thanks for the error checking. I really messed up ;) I will correct it.
I prefer not to create additional header files to reduce potential conflicts with other libraries. Although they could be hidden in a subfolder inside «src».
Corrections were uploaded
"setPressedState" is much clearer. I have a class in my current project that's very similar 😉 . I think you can re-use the state attribute to avoid increasing memory usage. Would it be possible to close this PR and open a new one for your "Button" branch?
Yes @jamesmyatt
Pull request closed