development #4
@@ -4,10 +4,13 @@ class Reader
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
unsigned long lastDebounceTime = 0;
|
unsigned long lastDebounceTime = 0;
|
||||||
bool lastButtonState = LOW;
|
bool lastButtonStateNO = LOW;
|
||||||
bool buttonState = HIGH;
|
bool buttonStateNO = HIGH;
|
||||||
|
bool lastButtonStateNC = HIGH;
|
||||||
|
bool buttonStateNC = LOW;
|
||||||
int lastPin;
|
int lastPin;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool debounceRead(int buttonPin);
|
bool debounceReadNO(int buttonPin);
|
||||||
|
bool debounceReadNC(int buttonPin);
|
||||||
};
|
};
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
#include <commonFunctions.h>
|
#include <commonFunctions.h>
|
||||||
#include <constants.h>
|
#include <constants.h>
|
||||||
|
|
||||||
bool Reader::debounceRead(int buttonPin)
|
bool Reader::debounceReadNO(int buttonPin)
|
||||||
{
|
{
|
||||||
bool reading = digitalRead(buttonPin);
|
bool reading = digitalRead(buttonPin);
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ bool Reader::debounceRead(int buttonPin)
|
|||||||
|
|
||||||
bool buttonPressed = false;
|
bool buttonPressed = false;
|
||||||
|
|
||||||
if (reading != lastButtonState && lastPin == buttonPin)
|
if (reading != lastButtonStateNO && lastPin == buttonPin)
|
||||||
{
|
{
|
||||||
lastDebounceTime = millis(); // reset debounce timer
|
lastDebounceTime = millis(); // reset debounce timer
|
||||||
}
|
}
|
||||||
@@ -21,16 +21,49 @@ bool Reader::debounceRead(int buttonPin)
|
|||||||
if ((millis() - lastDebounceTime) > DEBOUNCE_DELAY)
|
if ((millis() - lastDebounceTime) > DEBOUNCE_DELAY)
|
||||||
{
|
{
|
||||||
// If button state is stable and just changed to pressed
|
// If button state is stable and just changed to pressed
|
||||||
if (reading == HIGH && buttonState == LOW)
|
if (reading == HIGH && buttonStateNO == LOW)
|
||||||
{
|
{
|
||||||
buttonPressed = true;
|
buttonPressed = true;
|
||||||
}
|
}
|
||||||
buttonState = reading;
|
buttonStateNO = reading;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastPin == buttonPin)
|
if (lastPin == buttonPin)
|
||||||
{
|
{
|
||||||
lastButtonState = reading;
|
lastButtonStateNO = reading;
|
||||||
|
}
|
||||||
|
return buttonPressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Reader::debounceReadNC(int buttonPin)
|
||||||
|
{
|
||||||
|
bool reading = digitalRead(buttonPin);
|
||||||
|
|
||||||
|
if (reading == LOW)
|
||||||
|
{
|
||||||
|
lastPin = buttonPin;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool buttonPressed = false;
|
||||||
|
|
||||||
|
if (reading != lastButtonStateNC && lastPin == buttonPin)
|
||||||
|
{
|
||||||
|
lastDebounceTime = millis(); // reset debounce timer
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((millis() - lastDebounceTime) > DEBOUNCE_DELAY)
|
||||||
|
{
|
||||||
|
// If button state is stable and just changed to pressed
|
||||||
|
if (reading == LOW && buttonStateNC == HIGH)
|
||||||
|
{
|
||||||
|
buttonPressed = true;
|
||||||
|
}
|
||||||
|
buttonStateNC = reading;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastPin == buttonPin)
|
||||||
|
{
|
||||||
|
lastButtonStateNC = reading;
|
||||||
}
|
}
|
||||||
return buttonPressed;
|
return buttonPressed;
|
||||||
}
|
}
|
||||||
28
src/main.cpp
28
src/main.cpp
@@ -42,39 +42,39 @@ void loop()
|
|||||||
{
|
{
|
||||||
updateLeds(maxVolume);
|
updateLeds(maxVolume);
|
||||||
|
|
||||||
// // SW1 - Staff Volume Up
|
// SW1 - Staff Volume Up
|
||||||
// if (!reader.debounceRead(BTN_STAFF_UP))
|
if (reader.debounceReadNC(BTN_STAFF_UP))
|
||||||
// {
|
{
|
||||||
// staffVolumeUp(&maxVolume);
|
staffVolumeUp(&maxVolume);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // SW2 - Staff Volume Down
|
// SW2 - Staff Volume Down
|
||||||
// if (!reader.debounceRead(BTN_STAFF_DWN))
|
if (reader.debounceReadNC(BTN_STAFF_DWN))
|
||||||
// {
|
{
|
||||||
// staffVolumeDown(maxVolume, &userVolume, &oldUserVolume);
|
staffVolumeDown(maxVolume, &userVolume, &oldUserVolume);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// Remote D - Mute
|
// Remote D - Mute
|
||||||
if (reader.debounceRead(REMOTE_D))
|
if (reader.debounceReadNO(REMOTE_D))
|
||||||
{
|
{
|
||||||
mute(&userVolume, &oldUserVolume, maxVolume);
|
mute(&userVolume, &oldUserVolume, maxVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remote A - Significantly Lower Volume
|
// Remote A - Significantly Lower Volume
|
||||||
if (reader.debounceRead(REMOTE_A))
|
if (reader.debounceReadNO(REMOTE_A))
|
||||||
{
|
{
|
||||||
lowerVolume(&userVolume, &oldUserVolume, maxVolume);
|
lowerVolume(&userVolume, &oldUserVolume, maxVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remote B - Volume Up
|
// Remote B - Volume Up
|
||||||
// Make sure we are not is a state of mute or lowered
|
// Make sure we are not is a state of mute or lowered
|
||||||
if (reader.debounceRead(REMOTE_B) && !(oldUserVolume > userVolume))
|
if (reader.debounceReadNO(REMOTE_B) && !(oldUserVolume > userVolume))
|
||||||
{
|
{
|
||||||
volumeUp(&userVolume, &oldUserVolume, maxVolume);
|
volumeUp(&userVolume, &oldUserVolume, maxVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remote C - Volume Down
|
// Remote C - Volume Down
|
||||||
if (reader.debounceRead(REMOTE_C) && !(oldUserVolume > userVolume))
|
if (reader.debounceReadNO(REMOTE_C) && !(oldUserVolume > userVolume))
|
||||||
{
|
{
|
||||||
volumeDown(&userVolume, &oldUserVolume);
|
volumeDown(&userVolume, &oldUserVolume);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user