diff --git a/include/commonFunctions.h b/include/commonFunctions.h index 473d67b..55c6527 100644 --- a/include/commonFunctions.h +++ b/include/commonFunctions.h @@ -1,31 +1,19 @@ #pragma once -class Reader -{ -private: - unsigned long lastDebounceTime = 0; - bool lastButtonStateNO = LOW; - bool buttonStateNO = HIGH; - bool lastButtonStateNC = HIGH; - bool buttonStateNC = LOW; - int lastPin; +/** + * @brief Function used to read state of a normally open(LOW) button + * + * @param buttonPin The pin of the button + * @return true + * @return false + */ +bool debounceReadNO(int buttonPin); -public: - /** - * @brief Function used to read state of a normally open(LOW) button - * - * @param buttonPin The pin of the button - * @return true - * @return false - */ - bool debounceReadNO(int buttonPin); - - /** - * @brief Function used to read state of a normally closed(HIGH) button - * - * @param buttonPin The pin of the button - * @return true - * @return false - */ - bool debounceReadNC(int buttonPin); -}; \ No newline at end of file +/** + * @brief Function used to read state of a normally closed(HIGH) button + * + * @param buttonPin The pin of the button + * @return true + * @return false + */ +bool debounceReadNC(int buttonPin); diff --git a/src/commonFunctions.cpp b/src/commonFunctions.cpp index b04c79c..0392a7c 100644 --- a/src/commonFunctions.cpp +++ b/src/commonFunctions.cpp @@ -13,6 +13,13 @@ #include #include +unsigned long lastDebounceTime = 0; +bool lastButtonStateNO = LOW; +bool buttonStateNO = HIGH; +bool lastButtonStateNC = HIGH; +bool buttonStateNC = LOW; +int lastPin; + /** * @brief Function used to read state of a normally open(LOW) button * @@ -20,7 +27,7 @@ * @return true * @return false */ -bool Reader::debounceReadNO(int buttonPin) +bool debounceReadNO(int buttonPin) { bool reading = digitalRead(buttonPin); @@ -60,7 +67,7 @@ bool Reader::debounceReadNO(int buttonPin) * @return true * @return false */ -bool Reader::debounceReadNC(int buttonPin) +bool debounceReadNC(int buttonPin) { bool reading = digitalRead(buttonPin); diff --git a/src/main.cpp b/src/main.cpp index 4ec4343..7d70740 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,8 +10,6 @@ int maxVolume = 64; int userVolume = 64; int oldUserVolume = userVolume; -Reader reader; - void setup() { pinMode(LED_HIGH, OUTPUT); // Green @@ -45,39 +43,39 @@ void loop() updateLeds(maxVolume); // SW1 - Staff Volume Up - if (reader.debounceReadNC(BTN_STAFF_UP)) + if (debounceReadNC(BTN_STAFF_UP)) { staffVolumeUp(&maxVolume); } // SW2 - Staff Volume Down - if (reader.debounceReadNC(BTN_STAFF_DWN)) + if (debounceReadNC(BTN_STAFF_DWN)) { staffVolumeDown(&maxVolume, &userVolume, &oldUserVolume); } // Remote D - Mute - if (reader.debounceReadNO(REMOTE_D)) + if (debounceReadNO(REMOTE_D)) { mute(&userVolume, &oldUserVolume, maxVolume); } // Remote A - Significantly Lower Volume - if (reader.debounceReadNO(REMOTE_A)) + if (debounceReadNO(REMOTE_A)) { lowerVolume(&userVolume, &oldUserVolume, maxVolume); } // Remote B - Volume Up // Make sure we are not is a state of mute or lowered - if (reader.debounceReadNO(REMOTE_B) && !(oldUserVolume > userVolume)) + if (debounceReadNO(REMOTE_B) && !(oldUserVolume > userVolume)) { volumeUp(&userVolume, &oldUserVolume, maxVolume); } // Remote C - Volume Down // Make sure we are not is a state of mute or lowered - if (reader.debounceReadNO(REMOTE_C) && !(oldUserVolume > userVolume)) + if (debounceReadNO(REMOTE_C) && !(oldUserVolume > userVolume)) { volumeDown(&userVolume, &oldUserVolume); }