added rainbow_random animation
This commit is contained in:
parent
51e3178414
commit
53879d6546
1 changed files with 52 additions and 0 deletions
52
rainbow_random.ino
Normal file
52
rainbow_random.ino
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/******************************* PLANAR FLOP 3D *******************************\
|
||||
| Found on the internet.... |
|
||||
| |
|
||||
| Modified By: S. Dugre to use asynchronous timer |
|
||||
\******************************************************************************/
|
||||
|
||||
byte spectrum[24][3] = {
|
||||
{8,0,0},{7,1,0},{6,2,0},{5,3,0},{4,4,0},{3,5,0},{2,6,0},{1,7,0},
|
||||
{0,8,0},{0,7,1},{0,6,2},{0,5,3},{0,4,4},{0,3,5},{0,2,6},{0,1,7},
|
||||
{0,0,8},{1,0,7},{2,0,6},{3,0,5},{4,0,4},{5,0,3},{6,0,2},{7,0,1},
|
||||
};
|
||||
|
||||
byte cube[4][4][4];
|
||||
byte x;
|
||||
byte y;
|
||||
byte z;
|
||||
|
||||
void rainbow_random() {
|
||||
|
||||
if (currentState != lastState) {
|
||||
|
||||
lastState = currentState;
|
||||
Serial.print("New State = ");
|
||||
Serial.println(currentState);
|
||||
|
||||
randomSeed(analogRead(0));
|
||||
for (byte x = 0; x <= 3; x++) {
|
||||
for (byte y = 0; y <= 3; y++) {
|
||||
for (byte z = 0; z <= 3; z++) {
|
||||
cube[x][y][z] = random(24);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (byte x = 0; x <= 3; x++) {
|
||||
for (byte y = 0; y <= 3; y++) {
|
||||
for (byte z = 0; z <= 3; z++) {
|
||||
byte val = cube[x][y][z];
|
||||
drawLed(red, spectrum[val][0],x,y,z);
|
||||
drawLed(green,spectrum[val][1],x,y,z);
|
||||
drawLed(blue, spectrum[val][2],x,y,z);
|
||||
if ((x+y+z) % 2 == 0) { cube[x][y][z] = (val+1) % 24;}
|
||||
else { cube[x][y][z] = val == 0 ? 23 : val-1;}
|
||||
}
|
||||
}
|
||||
}
|
||||
flushBuffer();
|
||||
clearBuffer();
|
||||
delay(30);
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue