Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
|| @parameter buttonMode indicates BUTTON_PULLUP or BUTTON_PULLDOWN resistor
*/
Button::Button(uint8_t buttonPin, uint8_t buttonMode){
pin=buttonPin;
pin=buttonPin;
pinMode(pin,INPUT);

buttonMode==BUTTON_PULLDOWN ? pulldown() : pullup(buttonMode);
Expand All @@ -56,7 +56,7 @@ void Button::pullup(uint8_t buttonMode)
mode=BUTTON_PULLUP;
if (buttonMode == BUTTON_PULLUP_INTERNAL)
{
digitalWrite(pin,HIGH);
pinMode(pin,INPUT_PULLUP);
}
}

Expand All @@ -78,7 +78,8 @@ void Button::pulldown(void)
|| @return true if button is pressed
*/
bool Button::isPressed(void)
{
{

//save the previous value
bitWrite(state,PREVIOUS,bitRead(state,CURRENT));

Expand Down Expand Up @@ -282,4 +283,4 @@ unsigned int Button::holdTime() const { if (pressedStartTime!=-1) { return milli
bool Button::operator==(Button &rhs)
{
return (this==&rhs);
}
}
6 changes: 3 additions & 3 deletions Button.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
||
|| @description
|| | This is a Hardware Abstraction Library for Buttons
|| | It providea an easy way of handling buttons
|| | It provides an easy way of handling buttons
|| #
||
|| @license LICENSE_REPLACE
Expand Down Expand Up @@ -56,7 +56,7 @@ class Button {
uint8_t pin;
uint8_t mode;
uint8_t state;
unsigned int pressedStartTime;
unsigned long pressedStartTime;
unsigned int holdEventThreshold;
buttonEventHandler cb_onPress;
buttonEventHandler cb_onRelease;
Expand All @@ -66,4 +66,4 @@ class Button {
bool triggeredHoldEvent;
};

#endif
#endif
2 changes: 1 addition & 1 deletion Examples/Button/Button.ino
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
|| Wiring:
|| GND -----/ ------ pin 12
*/
Button button = Button(12,PULLUP);
Button button = Button(12,BUTTON_PULLUP);

void setup(){
pinMode(13,OUTPUT); //debug to led 13
Expand Down