Millis() not updating (ig. a interrupt takes to long)

Sure you can do it there, but learning to do it on an AVR is also an excellent exercise in better coding. You could do it with a PC, too, if your just wanting to throw money at it.

Seriously, there's a lot of scope for doing it on an Uno, and no reason not to. If you want to do something with an ESP32 as a learning exercise, that's different, but don't buy a caddy for the trip to the local convenience store.

No, an ESP32 isn't a simplification. Not in any measurable sense I can think of.

1 Like

yes but how should i then use for loops for exampe moving a led up and down with a delay of 500ms. how would you do that so that the cube still gets rendered?

another if clause, same millis() approach, different time variables, would be one way. Right after the first one.

1 Like

After that's working, then think about what's going on. You've got multiple loops within your update. Why? loop() is looping, remember.
There are many 'design patterns' you could employ here. Trotting out your final target one facet at a time makes it impossible for me, or anyone else, to pick the 'best', or most appropriate, pattern to accomplish what you want.
Tell us more about the whole scope of your project.

Tell us more about the whole scope of your project.

Indeed. Explain more about the animations, how many you expect to have, and where the cube[x][y][z] values are going to come from.

ok. so right now i like these four animations.

  1. voxel
  2. voxelFillup (its kinda like tetris)
  3. randomCorner
  4. cubeInsideCube

voxel:
at the start i go through every x and y position and randomly select if the led is lit on the top or on the bottom. Then i randomly select a x y pos. again and look if the led is lit at the top / bottom and then "push" the led to the top / bottom one by one.

voxelFillup:
randomly selecting x y pos. and "dropping" a led from the top to the bottom. they stack on top in each collumn and when a collumn is full it blinks 3 times and then the whole collumn "falls" out the bottom.

randomCorner:
it starts with the outlines of the cube lit and then contracts and expands into / from a random corner.

cubeInsideCube:
its basically this in static form:
HCube-Folded

All of these animations already work and exist. They are running right now on my cube. But the code implementation with the render handling is the thing i want to change.

And the cube[x][y][z] come from the animation handling. either the value is 1 or 0 (lit or off)

Nice. However, we've been working at "See Dick Run" level, while you fail to mention your desire is to write "Moby Dick". It is NOT an inaccurate analogy.
Now that we know where you want to go, and how complex it is, I'd like to see those codes posted. You might actually have reason to move to ESP32, not sure.

But i have a esp32 lying around and i am going to try it

This is my loop:

void loop() {
  reload = true;
  for(int i = 0; i < 6; i++) {
    randomCorner();
  }
  reload = true;
  voxel(1000);
  reload = true;
  for(int i = 0; i < 30; i++) {
    cubeInsideCube();
  }
  reload = true;
  voxelFillUp(1500);
}

And here is the voxel one:

int randX;
int randY;
int randXBefore = 0;
int randYBefore = 0;
void voxel(int repeat) {
  if(reload) {
    clearCube();
    for(int y = 0; y < 8; y++) {
      for(int x = 0; x < 8; x++) {
        cube[x][y][random(0, 2) * 7] = 1;
      }
    }
    reload = false;
  }
  for(int countRepeat = 0; countRepeat < repeat; countRepeat++) {
    do {
      randX = random(0, 8);
    } while(randX == randXBefore);
    do {
      randY = random(0, 8);
    } while(randY == randYBefore);

    if(getState(randX, randY, 7)) {
      shiftDown(randX, randY, 7, 0);
    } else {
      shiftUp(randX, randY, 0, 7);
    }
    randXBefore = randX;
    randYBefore = randY;
  }
}

void shiftUp(int x, int y, int startVal, int endVal) {
  for(int z = startVal; z < endVal; z++) {
    cube[x][y][z] = 0;
    cube[x][y][z + 1] = 1;
    for(int renderTime = 0; renderTime < 5; renderTime++) {
      renderCube(render);
    }
  }
}

void shiftDown(int x, int y, int startVal, int endVal) {
  for(int z = startVal; z > endVal; z--) {
    cube[x][y][z] = 0;
    cube[x][y][z - 1] = 1;
    for(int renderTime = 0; renderTime < 5; renderTime++) {
      renderCube(render);
    }
  }
}

void clearCube() {
  for(int z = 0; z < 8; z++) {
    for(int y = 0; y < 8; y++) {
      for(int x = 0; x < 8; x++) {
        cube[x][y][z] = 0;
      }
    }
  }
}

i mean it does work flawless.
maybe i forgot the rule: if it works don't touch it xD

I love watching noobs re-invent the wheel. But the clearCube function made me laugh the most. You should also determine the cost of using non constant looping variables.

Fairly obvious, I wonder how many more amateur mistakes there are? He might benefit from looking at how game programmers do it.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.