Skip to content

Commit

Permalink
Moving heads demo
Browse files Browse the repository at this point in the history
  • Loading branch information
ewowi committed Jan 29, 2024
1 parent c3c0f17 commit 1076cdc
Show file tree
Hide file tree
Showing 6 changed files with 1,338 additions and 1,315 deletions.
6 changes: 6 additions & 0 deletions data/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ function preview3D(canvasNode, buffer) {
}
}

// controls.rotateSpeed = 0.4;
console.log(buffer[1], buffer[2], buffer[3]);
scene.rotation.x = buffer[1];
scene.rotation.y = buffer[2];
scene.rotation.z = buffer[3];

controls.update(); // apply orbit controls

if (mousePointer) {
Expand Down
26 changes: 15 additions & 11 deletions src/App/AppEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,6 @@ class GEQEffect:public Effect {

const int NUM_BANDS = NUM_GEQ_CHANNELS ; // map(SEGMENT.custom1, 0, 255, 1, 16);

uint8_t *fftResult = wledAudioMod->fftResults;
#ifdef SR_DEBUG
uint8_t samplePeak = *(uint8_t*)um_data->u_data[3];
#endif
Expand Down Expand Up @@ -732,15 +731,15 @@ class GEQEffect:public Effect {
uint8_t frBand = ((NUM_BANDS < 16) && (NUM_BANDS > 1)) ? map(band, 0, NUM_BANDS - 1, 0, 15):band; // always use full range. comment out this line to get the previous behaviour.
// frBand = constrain(frBand, 0, 15); //WLEDMM can never be out of bounds (I think...)
uint16_t colorIndex = frBand * 17; //WLEDMM 0.255
uint16_t bandHeight = fftResult[frBand]; // WLEDMM we use the original ffResult, to preserve accuracy
uint16_t bandHeight = wledAudioMod->fftResults[frBand]; // WLEDMM we use the original ffResult, to preserve accuracy

// WLEDMM begin - smooth out bars
if ((pos.x > 0) && (pos.x < (leds.size.x-1)) && (smoothBars)) {
// get height of next (right side) bar
uint8_t nextband = (remaining < 1)? band +1: band;
nextband = constrain(nextband, 0, 15); // just to be sure
frBand = ((NUM_BANDS < 16) && (NUM_BANDS > 1)) ? map(nextband, 0, NUM_BANDS - 1, 0, 15):nextband; // always use full range. comment out this line to get the previous behaviour.
uint16_t nextBandHeight = fftResult[frBand];
uint16_t nextBandHeight = wledAudioMod->fftResults[frBand];
// smooth Band height
bandHeight = (7*bandHeight + 3*lastBandHeight + 3*nextBandHeight) / 12; // yeees, its 12 not 13 (10% amplification)
bandHeight = constrain(bandHeight, 0, 255); // remove potential over/underflows
Expand Down Expand Up @@ -802,17 +801,15 @@ class AudioRings:public RingEffect {
}

void loop(Leds &leds) {
uint8_t *fftResult = wledAudioMod->fftResults;

for (int i = 0; i < 7; i++) { // 7 rings

uint8_t val;
if(mdl->getValue("inWards").as<bool>()) {
val = fftResult[(i*2)];
val = wledAudioMod->fftResults[(i*2)];
}
else {
int b = 14 -(i*2);
val = fftResult[b];
val = wledAudioMod->fftResults[b];
}

// Visualize leds to the beat
Expand All @@ -828,8 +825,7 @@ class AudioRings:public RingEffect {

}
void setRingFromFtt(Leds &leds, int index, int ring) {
uint8_t *fftResult = wledAudioMod->fftResults;
uint8_t val = fftResult[index];
uint8_t val = wledAudioMod->fftResults[index];
// Visualize leds to the beat
CRGB color = ColorFromPalette(palette, val, 255);
color.nscale8_video(val);
Expand Down Expand Up @@ -864,8 +860,6 @@ class FreqMatrix:public Effect {
uint8_t highBin = mdl->getValue("High bin");
uint8_t sensitivity10 = mdl->getValue("Sensivity");

uint8_t *fftResult = wledAudioMod->fftResults;

uint8_t secondHand = (speed < 255) ? (micros()/(256-speed)/500 % 16) : 0;
if((speed > 254) || (*aux0 != secondHand)) { // WLEDMM allow run run at full speed
*aux0 = secondHand;
Expand Down Expand Up @@ -974,6 +968,16 @@ class Effects {

effects[leds.fx%effects.size()]->loop(leds);

#ifdef USERMOD_WLEDAUDIO

if (mdl->getValue("mHead") ) {
leds.head.x = wledAudioMod->fftResults[3];
leds.head.y = wledAudioMod->fftResults[8];
leds.head.z = wledAudioMod->fftResults[13];
}

#endif

call++;

EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
Expand Down
2 changes: 2 additions & 0 deletions src/App/AppLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class Leds {
uint16_t nrOfLeds = 64; //amount of virtual leds (calculated by projection)

Coord3D size = {8,8,1};

Coord3D head = {0,0,0};

uint8_t fx = -1;
uint8_t projectionNr = -1;
Expand Down
3 changes: 3 additions & 0 deletions src/App/AppModFixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class AppModFixture:public SysModule {
}
//new values
buffer[0] = 1; //userFun id
buffer[1] = lds->leds.head.x;
buffer[2] = lds->leds.head.y;
buffer[3] = lds->leds.head.y;
// buffer[1] = fixture.nrOfLeds/256;
// buffer[2] = fixture.nrOfLeds%256;
// buffer[4] = max(fixture.nrOfLeds * SysModWeb::ws->count()/200, 16U); //interval in ms * 10, not too fast
Expand Down
6 changes: 6 additions & 0 deletions src/App/AppModLeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ class AppModLeds:public SysModule {
web->addResponse(var["id"], "label", "Count");
});

#ifdef USERMOD_WLEDAUDIO
ui->initCheckBox(parentVar, "mHead", false, false, [](JsonObject var) { //uiFun
web->addResponse(var["id"], "label", "Moving heads");
web->addResponse(var["id"], "comment", "Move on GEQ");
});
#endif

#ifdef USERMOD_E131
// if (e131mod->isEnabled) {
Expand Down
Loading

0 comments on commit 1076cdc

Please sign in to comment.