From 9e98c886f742e8e7471a83db70f7172554911bc6 Mon Sep 17 00:00:00 2001 From: starcalc Date: Tue, 2 Jul 2019 20:29:09 +0200 Subject: [PATCH] vu meter (re)added --- esp-pixelbox.ino | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/esp-pixelbox.ino b/esp-pixelbox.ino index 004c232..8b797c9 100644 --- a/esp-pixelbox.ino +++ b/esp-pixelbox.ino @@ -77,6 +77,39 @@ bool onSetPixel(const HomieRange& range, const String& value) { homieNode.setProperty("pixel_" + String(range.index)).send(value); } +bool onSetVU(const HomieRange& range, const String& value) { + strip.Stop(); // Do not show any "effects" anymore + strip.clear(); // All pixels to black + String remaining = value; + String current; + int i = 0; + do + { + if (remaining.length() == 1) + { + current = remaining.substring(0,1); + } else { + current = remaining.substring(0,2); + } + int currentvalue = (int) strtol(¤t[0], NULL, 10); + // White peak + strip.setPixelColor(strip.numToPos(56+i-currentvalue*8), 16777215); // White dot + // Shaded bar "below" the peak + if (currentvalue>0) + { + for (int j=currentvalue-1;j>-1;j--) + { + strip.setPixelColor(strip.numToPos(56+i-j*8), 4276545); // Greyscale + } + } + i++; + remaining = remaining.substring(2); + } while (remaining.length()>0); // TODO: Not bigger than strip + strip.show(); + homieNode.setProperty("VU_" + String(range.index)).send(value); +} + + bool onSetBrightness(const HomieRange& range, const String& value) { long brightness = value.toInt(); if (brightness < 0 || brightness > 255) { @@ -320,7 +353,7 @@ void setup() { homieNode.advertise("icon").settable(onSetIcon); homieNode.advertise("next").settable(onSetNext); homieNode.advertiseRange("pixels", 0, (NUMPIXELS - 1) * 7).settable(onSetPixels); - + homieNode.advertiseRange("vu", 0, sqrt(NUMPIXELS)-1).settable(onSetVU); strip.begin(); strip.clear();