Added previous duration

This commit is contained in:
Thomas O Fredericks
2018-09-11 10:09:57 -04:00
parent d3ef0365eb
commit d422d7c054
2 changed files with 12 additions and 6 deletions
+4 -4
View File
@@ -107,12 +107,12 @@ bool Bounce::update()
return getStateFlag(CHANGED_STATE);
}
/*
// WIP HELD
unsigned long Bounce::held() {
unsigned long Bounce::previousDuration() {
return durationOfPreviousState;
}
*/
unsigned long Bounce::duration() {
return (millis() - stateChangeLastTime);
}
@@ -120,7 +120,7 @@ unsigned long Bounce::duration() {
inline void Bounce::changeState() {
toggleStateFlag(DEBOUNCED_STATE);
setStateFlag(CHANGED_STATE) ;
// WIP HELD : durationOfPreviousState = millis() - stateChangeLastTime;
durationOfPreviousState = millis() - stateChangeLastTime;
stateChangeLastTime = millis();
}
+8 -2
View File
@@ -164,8 +164,14 @@ class Bounce
unsigned long duration();
/**
@brief Returns the duration in milliseconds of the previous state.
// WIP HELD : unsigned long held(); // Returns the duration the previous state was held
Takes the values of duration() once the pin changes state.
@return The duration in milliseconds (unsigned long) of the previous state.
*/
unsigned long previousDuration();
protected:
unsigned long previous_millis;
@@ -173,7 +179,7 @@ class Bounce
uint8_t state;
uint8_t pin;
unsigned long stateChangeLastTime;
// WIP HELD : unsigned long durationOfPreviousState;
unsigned long durationOfPreviousState;
virtual bool readCurrentState() { return digitalRead(pin); }
virtual void setPinMode(int pin, int mode) {
#if defined(ARDUINO_STM_NUCLEO_F103RB) || defined(ARDUINO_GENERIC_STM32F103C)