diff --git a/Button.cpp b/Button.cpp index f6174c1..d4a11ea 100755 --- a/Button.cpp +++ b/Button.cpp @@ -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); @@ -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); } } @@ -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)); @@ -282,4 +283,4 @@ unsigned int Button::holdTime() const { if (pressedStartTime!=-1) { return milli bool Button::operator==(Button &rhs) { return (this==&rhs); -} \ No newline at end of file +} diff --git a/Button.h b/Button.h index c1528d9..6cb2497 100755 --- a/Button.h +++ b/Button.h @@ -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 @@ -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; @@ -66,4 +66,4 @@ class Button { bool triggeredHoldEvent; }; -#endif \ No newline at end of file +#endif diff --git a/Examples/Button/Button.ino b/Examples/Button/Button.ino index faf3c25..33f48ca 100644 --- a/Examples/Button/Button.ino +++ b/Examples/Button/Button.ino @@ -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