carlynorama/Arduino-Library-Button

Use dafault parameters

Opened this issue · 0 comments

Instead of

//---------------------------------------------------- onPress 
bool Button::onPress(void){
    return _justPressed;
}   
//------------------------------------------------ overload
    
bool Button::onPress(bool refreshPinData){
    if (refreshPinData) {   
      listen();
      return onPress();  
    } else {
      return onPress(); 
    }
}```

You can write just 

Header:
bool Button::onPress(bool refreshPinData=false);
Source:
bool Button::onPress(bool refreshPinData){
if (refreshPinData) {
listen();
}
return justPressed_;
}```
Whic is much shorter and therefore much more readable. And calling to onPress(true) would be much faster.

Or pull #3