vu meter (re)added
This commit is contained in:
parent
aaea4c0353
commit
9e98c886f7
|
@ -77,6 +77,39 @@ bool onSetPixel(const HomieRange& range, const String& value) {
|
||||||
homieNode.setProperty("pixel_" + String(range.index)).send(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) {
|
bool onSetBrightness(const HomieRange& range, const String& value) {
|
||||||
long brightness = value.toInt();
|
long brightness = value.toInt();
|
||||||
if (brightness < 0 || brightness > 255) {
|
if (brightness < 0 || brightness > 255) {
|
||||||
|
@ -320,7 +353,7 @@ void setup() {
|
||||||
homieNode.advertise("icon").settable(onSetIcon);
|
homieNode.advertise("icon").settable(onSetIcon);
|
||||||
homieNode.advertise("next").settable(onSetNext);
|
homieNode.advertise("next").settable(onSetNext);
|
||||||
homieNode.advertiseRange("pixels", 0, (NUMPIXELS - 1) * 7).settable(onSetPixels);
|
homieNode.advertiseRange("pixels", 0, (NUMPIXELS - 1) * 7).settable(onSetPixels);
|
||||||
|
homieNode.advertiseRange("vu", 0, sqrt(NUMPIXELS)-1).settable(onSetVU);
|
||||||
|
|
||||||
strip.begin();
|
strip.begin();
|
||||||
strip.clear();
|
strip.clear();
|
||||||
|
|
Loading…
Reference in New Issue