From 2e6aa58cf99490d8211174b08f0cc834168d9083 Mon Sep 17 00:00:00 2001 From: Lyubomir Penev Date: Wed, 22 Oct 2025 13:18:43 +0200 Subject: [PATCH] Seperated potentiometer controlls --- include/README | 37 --------------------------- include/potControlls.h | 4 +++ src/main.cpp | 58 ++++++++++-------------------------------- src/potControlls.cpp | 31 ++++++++++++++++++++++ 4 files changed, 49 insertions(+), 81 deletions(-) delete mode 100644 include/README create mode 100644 include/potControlls.h create mode 100644 src/potControlls.cpp diff --git a/include/README b/include/README deleted file mode 100644 index 49819c0..0000000 --- a/include/README +++ /dev/null @@ -1,37 +0,0 @@ - -This directory is intended for project header files. - -A header file is a file containing C declarations and macro definitions -to be shared between several project source files. You request the use of a -header file in your project source file (C, C++, etc) located in `src` folder -by including it, with the C preprocessing directive `#include'. - -```src/main.c - -#include "header.h" - -int main (void) -{ - ... -} -``` - -Including a header file produces the same results as copying the header file -into each source file that needs it. Such copying would be time-consuming -and error-prone. With a header file, the related declarations appear -in only one place. If they need to be changed, they can be changed in one -place, and programs that include the header file will automatically use the -new version when next recompiled. The header file eliminates the labor of -finding and changing all the copies as well as the risk that a failure to -find one copy will result in inconsistencies within a program. - -In C, the convention is to give header files names that end with `.h'. - -Read more about using header files in official GCC documentation: - -* Include Syntax -* Include Operation -* Once-Only Headers -* Computed Includes - -https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/include/potControlls.h b/include/potControlls.h new file mode 100644 index 0000000..096b64b --- /dev/null +++ b/include/potControlls.h @@ -0,0 +1,4 @@ +#pragma once + +void potIncrement(); +void potDecrement(); \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index b507ec8..0fbfde9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,5 @@ #include +#include const int USER_STEPS = 2; const int STAFF_STEPS = 16; @@ -12,9 +13,7 @@ int lastButtonState = LOW; unsigned long lastDebounceTime = 0; unsigned long debounceDelay = 50; -void volumeUp(); -void volumeDown(); -bool debounceRead(); +bool debounceRead(int buttonPin); void setup() { @@ -38,7 +37,7 @@ void setup() for (int i = 0; i < 64; i++) { - volumeUp(); + potIncrement(); } } @@ -88,7 +87,7 @@ void loop() { for (int i = 0; i < (userVolume - maxVolume); i++) { - volumeDown(); + potDecrement(); } userVolume = maxVolume; @@ -118,7 +117,7 @@ void loop() for (int i = 0; i < maxVolume; i++) { - volumeUp(); + potIncrement(); } } else @@ -128,7 +127,7 @@ void loop() for (int i = 0; i < oldUserVolume; i++) { - volumeUp(); + potIncrement(); } } } @@ -137,7 +136,7 @@ void loop() // This is if the user is unmuted and is aksing to be muted for (int i = 0; i < 64; i++) { - volumeDown(); + potDecrement(); } oldUserVolume = userVolume; @@ -162,7 +161,7 @@ void loop() for (int i = 0; i < maxVolume; i++) { - volumeUp(); + potIncrement(); } } else @@ -172,7 +171,7 @@ void loop() for (int i = 0; i < oldUserVolume; i++) { - volumeUp(); + potIncrement(); } } } @@ -181,7 +180,7 @@ void loop() // This is if the user is not lowered and is aksing to be lowered for (int i = 0; i < userVolume - 10; i++) { - volumeDown(); + potDecrement(); } oldUserVolume = userVolume; @@ -197,7 +196,7 @@ void loop() { for (int i = 0; i < maxVolume - userVolume; i++) { - volumeUp(); + potIncrement(); } userVolume = maxVolume; @@ -207,7 +206,7 @@ void loop() { for (int i = 0; i < USER_STEPS; i++) { - volumeUp(); + potIncrement(); } userVolume += USER_STEPS; @@ -222,7 +221,7 @@ void loop() { for (int i = 0; i < userVolume; i++) { - volumeDown(); + potDecrement(); } userVolume = 0; @@ -232,7 +231,7 @@ void loop() { for (int i = 0; i < USER_STEPS; i++) { - volumeDown(); + potDecrement(); } userVolume -= USER_STEPS; @@ -241,35 +240,6 @@ void loop() } } -void volumeUp() -{ - digitalWrite(9, HIGH); - delay(1); - digitalWrite(10, LOW); - delay(1); - digitalWrite(9, LOW); - delay(1); - digitalWrite(9, HIGH); - delay(1); - digitalWrite(10, HIGH); - delay(1); - digitalWrite(9, LOW); - digitalWrite(10, HIGH); -} - -void volumeDown() -{ - digitalWrite(9, LOW); - delay(1); - digitalWrite(10, LOW); - delay(1); - digitalWrite(9, HIGH); - delay(1); - digitalWrite(9, LOW); - delay(1); - digitalWrite(10, HIGH); -} - bool debounceRead(int buttonPin) { int reading = digitalRead(buttonPin); diff --git a/src/potControlls.cpp b/src/potControlls.cpp new file mode 100644 index 0000000..9a44a7f --- /dev/null +++ b/src/potControlls.cpp @@ -0,0 +1,31 @@ +#include +#include + +void potIncrement() +{ + digitalWrite(9, HIGH); + delay(1); + digitalWrite(10, LOW); + delay(1); + digitalWrite(9, LOW); + delay(1); + digitalWrite(9, HIGH); + delay(1); + digitalWrite(10, HIGH); + delay(1); + digitalWrite(9, LOW); + digitalWrite(10, HIGH); +} + +void potDecrement() +{ + digitalWrite(9, LOW); + delay(1); + digitalWrite(10, LOW); + delay(1); + digitalWrite(9, HIGH); + delay(1); + digitalWrite(9, LOW); + delay(1); + digitalWrite(10, HIGH); +} \ No newline at end of file