add working equalizer
This commit is contained in:
parent
699f1e12e7
commit
7ee666afa7
|
@ -690,6 +690,7 @@ void NeoPatterns::setupboxs() {
|
|||
boxs[0].right = 39;
|
||||
}
|
||||
|
||||
|
||||
void NeoPatterns::colorCircleSegment(uint8_t wheelid, uint32_t c){ //color a wheel segment
|
||||
for (int i=0;i<6;i++) {
|
||||
setPixelColor(boxcircle[wheelid][i], c);
|
||||
|
@ -847,4 +848,42 @@ uint32_t NeoPatterns::parseColor(String value) {
|
|||
|
||||
|
||||
|
||||
void NeoPatterns::Equalizer(uint8_t eqvalues[]){ //display equalizer (not used as "effect")
|
||||
//eqvalues[] of size 8, each contains a value from 0 to 8 (inclusive)
|
||||
setEqBar(0,eqvalues[0]);
|
||||
setEqBar(1,eqvalues[1]);
|
||||
setEqBar(2,eqvalues[2]);
|
||||
setEqBar(3,eqvalues[3]);
|
||||
setEqBar(4,eqvalues[4]);
|
||||
setEqBar(5,eqvalues[5]);
|
||||
setEqBar(6,eqvalues[6]);
|
||||
setEqBar(7,eqvalues[7]);
|
||||
setEqBar(8,eqvalues[7]);
|
||||
|
||||
setEqBar(17,eqvalues[0]);
|
||||
setEqBar(16,eqvalues[1]);
|
||||
setEqBar(15,eqvalues[2]);
|
||||
setEqBar(14,eqvalues[3]);
|
||||
setEqBar(13,eqvalues[4]);
|
||||
setEqBar(12,eqvalues[5]);
|
||||
setEqBar(11,eqvalues[6]);
|
||||
setEqBar(10,eqvalues[7]);
|
||||
setEqBar(9,eqvalues[7]);
|
||||
|
||||
|
||||
show();
|
||||
}
|
||||
//helper function
|
||||
void NeoPatterns::setEqBar(uint8_t barid,uint8_t pvalue){ //barid is the bar from ledEq array (vertical),pvalue is the amplitude
|
||||
for (uint8_t i=0;i<8;i++){
|
||||
uint8_t ledId=ledEq[barid][i];
|
||||
uint32_t backgroundColor=Color(0,0,0);
|
||||
if (i<pvalue){
|
||||
setPixelColor(ledId,Wheel((i*32+100)%256));
|
||||
}else{
|
||||
setPixelColor(ledId,backgroundColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -36,6 +36,8 @@ class NeoPatterns : public Adafruit_NeoPixel
|
|||
void PlasmaUpdate();
|
||||
void Radar(float radarspeed = 0.5,float radarthickness = 1, uint8_t interval = 50);
|
||||
void RadarUpdate();
|
||||
void Equalizer(uint8_t eqvalues[]);
|
||||
void setEqBar(uint8_t barid,uint8_t pvalue);
|
||||
|
||||
void SetColor1(uint32_t color);
|
||||
void SetColor2(uint32_t color);
|
||||
|
@ -71,7 +73,7 @@ class NeoPatterns : public Adafruit_NeoPixel
|
|||
{58,59,60,60,60,60},
|
||||
{61,62,63,63,63,63},
|
||||
{64,65,66,66,66,66},
|
||||
{67,68,69,69,69,69},
|
||||
{67,68,69,69,69,69}
|
||||
};
|
||||
/*uint8_t boxcircle[32][4]={
|
||||
{0,0,0,0}, //0
|
||||
|
@ -108,6 +110,28 @@ class NeoPatterns : public Adafruit_NeoPixel
|
|||
{69,69,69,69} //31
|
||||
};*/
|
||||
|
||||
uint8_t ledEq[18][8]={
|
||||
{23,20,17,14,11,8,8,8},
|
||||
{22,19,16,13,10,7,7,7},
|
||||
{21,18,15,12,9,6,6,6},
|
||||
{26,29,255,255,255,5,5,5},
|
||||
{25,28,255,255,255,4,4,4},
|
||||
{24,27,255,255,255,3,3,3},
|
||||
{34,33,32,31,30,2,2,2},
|
||||
{255,255,255,255,255,1,1,1},
|
||||
{255,255,255,255,255,0,0,0},
|
||||
|
||||
{255,255,255,255,255,69,69,69},
|
||||
{255,255,255,255,255,68,68,68},
|
||||
{39,38,37,36,35,67,67,67},
|
||||
{45,42,255,255,255,66,66,66},
|
||||
{44,41,255,255,255,65,65,65},
|
||||
{43,40,255,255,255,64,64,64},
|
||||
{48,51,54,57,60,63,63,63},
|
||||
{47,50,53,56,59,62,62,62},
|
||||
{46,49,52,55,58,61,61,61}
|
||||
};
|
||||
|
||||
void setupboxs();
|
||||
void colorBox(uint8_t boxid, uint32_t c);
|
||||
void colorCircleSegment(uint8_t segmentid, uint32_t c);
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
//Wemos D1 R2 mini
|
||||
//4M (1M SPIFFS)
|
||||
//80 MHz
|
||||
//115200
|
||||
#include <Homie.h>
|
||||
#include <ArduinoOTA.h>
|
||||
#include <Arduino.h>
|
||||
#include <SoftwareSerial.h>
|
||||
#include "NeoPatterns.h"
|
||||
#include <WiFiUdp.h>
|
||||
|
||||
#define PIN D7
|
||||
// #define BIGPIXELS 20
|
||||
|
@ -29,6 +34,10 @@ String output2 = "";
|
|||
|
||||
unsigned long lastMillis = 0;
|
||||
|
||||
WiFiUDP Udp;
|
||||
unsigned int localUdpPort = 4210; // local port to listen on
|
||||
char incomingPacket[255]; // buffer for incoming packets
|
||||
|
||||
|
||||
/*
|
||||
* 25 Boxen insgesamt
|
||||
|
@ -313,6 +322,7 @@ void setup() {
|
|||
|
||||
Homie.setup();
|
||||
|
||||
|
||||
strip.begin();
|
||||
strip.clear();
|
||||
strip.show();
|
||||
|
@ -337,6 +347,14 @@ void setup() {
|
|||
});
|
||||
|
||||
ArduinoOTA.begin();
|
||||
|
||||
while(WiFi.localIP().toString()=="0.0.0.0"){
|
||||
Serial.println(WiFi.localIP());
|
||||
delay(10);
|
||||
}
|
||||
Udp.begin(localUdpPort);
|
||||
Serial.printf("Now listening on UDP port %d \n", localUdpPort);
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
@ -392,4 +410,44 @@ void loop() {
|
|||
currentnumber = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//UDP
|
||||
int packetSize = Udp.parsePacket();
|
||||
if (packetSize)
|
||||
{
|
||||
// receive incoming UDP packets
|
||||
//Serial.printf("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());
|
||||
int len = Udp.read(incomingPacket, 255);
|
||||
if (len > 0)
|
||||
{
|
||||
incomingPacket[len] = 0;
|
||||
}
|
||||
//uint16_t data=incomingPacket[0]<<8 | incomingPacket[1];
|
||||
|
||||
//Serial.printf("UDP packet contents: %s\n", incomingPacket);
|
||||
|
||||
uint8_t bar[8];
|
||||
|
||||
|
||||
bar[0]=incomingPacket[0]%16;
|
||||
bar[1]=incomingPacket[0]/16;
|
||||
bar[2]=incomingPacket[1]%16;
|
||||
bar[3]=incomingPacket[1]/16;
|
||||
bar[4]=incomingPacket[2]%16;
|
||||
bar[5]=incomingPacket[2]/16;
|
||||
bar[6]=incomingPacket[3]%16;
|
||||
bar[7]=incomingPacket[3]/16;
|
||||
|
||||
strip.Equalizer(bar);
|
||||
|
||||
strip.Stop(); //Stop effect
|
||||
|
||||
//bar_ contains a number from 0 to 7 (inclusive)
|
||||
|
||||
|
||||
//printBinary(mapData(data));
|
||||
//shiftRelais(mapData(data));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue