Browse Source

Make VU meter symmetrical to center module

lua
Thomas Kolb 7 years ago
parent
commit
bac8df287c
1 changed files with 16 additions and 4 deletions
  1. 16
    4
      vumeter.lua

+ 16
- 4
vumeter.lua View File

@@ -1,5 +1,5 @@
1 1
 COOLDOWN_FACTOR = 0.9998
2
-FACTOR = 0.2
2
+FACTOR = 0.033
3 3
 
4 4
 num_modules = 20
5 5
 center_module = 10
@@ -44,21 +44,33 @@ function periodic()
44 44
   local brightness = rms / maxRMS
45 45
 
46 46
   for i = 1,num_modules do
47
-    if i <= num_modules * redEnergy / maxRedEnergy then
47
+    if i <= center_module and
48
+         center_module - i < center_module * redEnergy / maxRedEnergy or
49
+       i > center_module and
50
+         i - (center_module + 1) < (num_modules-center_module) * redEnergy / maxRedEnergy
51
+    then
48 52
       redTarget = brightness
49 53
     else
50 54
       redTarget = 0
51 55
     end
52 56
     red[i] = (1 - FACTOR) * red[i] + FACTOR * redTarget;
53 57
 
54
-    if i <= num_modules * greenEnergy / maxGreenEnergy then
58
+    if i <= center_module and
59
+         center_module - i < center_module * greenEnergy / maxGreenEnergy or
60
+       i > center_module and
61
+         i - (center_module + 1) < (num_modules-center_module) * greenEnergy / maxGreenEnergy
62
+    then
55 63
       greenTarget = brightness
56 64
     else
57 65
       greenTarget = 0
58 66
     end
59 67
     green[i] = (1 - FACTOR) * green[i] + FACTOR * greenTarget;
60 68
 
61
-    if i <= num_modules * blueEnergy / maxBlueEnergy then
69
+    if i <= center_module and
70
+         center_module - i < center_module * blueEnergy / maxBlueEnergy or
71
+       i > center_module and
72
+         i - (center_module + 1) < (num_modules-center_module) * blueEnergy / maxBlueEnergy
73
+    then
62 74
       blueTarget = brightness
63 75
     else
64 76
       blueTarget = 0

Loading…
Cancel
Save