diff --git a/src/main.cpp b/src/main.cpp index a5be1ee..07aaeea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,7 +5,6 @@ const int STAFF_STEPS = 16; int maxVolume = 64; int userVolume = 64; -int potPosition = 64; int oldUserVolume = userVolume; void volumeUp(); @@ -85,12 +84,16 @@ void loop() for (int i = 0; i < (userVolume - maxVolume); i++) { volumeDown(); - potPosition--; } userVolume = maxVolume; oldUserVolume = userVolume; } + + if (oldUserVolume > maxVolume) + { + oldUserVolume = maxVolume; + } delay(300); } } @@ -102,17 +105,37 @@ void loop() // Check if we are in a muted state if (oldUserVolume > userVolume) { + // This is if the user is muted and is asking to be unmuted + // Check if max volume has been lowered since mute if (oldUserVolume > maxVolume) { + // If the max volume has been lowered since mute, then set the user volume to the new max volume userVolume = maxVolume; + + for (int i = 0; i < maxVolume; i++) + { + volumeUp(); + } } else { + // If the max volume hasn't changed then, or the old user volume is lower than the new max - restore it to where it was userVolume = oldUserVolume; + + for (int i = 0; i < oldUserVolume; i++) + { + volumeUp(); + } } } else { + // This is if the user is unmuted and is aksing to be muted + for (int i = 0; i < userVolume; i++) + { + volumeDown(); + } + oldUserVolume = userVolume; userVolume = 0; }