Arduino-Library-Button icon indicating copy to clipboard operation
Arduino-Library-Button copied to clipboard

Use dafault parameters

Open kibergus opened this issue 13 years ago • 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 https://github.com/carlynorama/Arduino-Library-Button/pull/3

kibergus avatar Aug 15 '12 16:08 kibergus