Arduino 368, mehr Effekte, mehr Helligkeitsstufen
This commit is contained in:
parent
2a3c9fc96a
commit
d55d2036ed
7 changed files with 224 additions and 13 deletions
|
|
@ -4,7 +4,7 @@
|
|||
# Please make sure to read documentation with examples first
|
||||
# http://docs.platformio.org/en/stable/projectconf.html
|
||||
#
|
||||
[env:nanoatmega168]
|
||||
[env:nanoatmega328]
|
||||
platform = atmelavr
|
||||
framework = arduino
|
||||
board = nanoatmega168
|
||||
board = nanoatmega328
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
CubeRegister myRegister = CubeRegister();
|
||||
|
||||
#define CUBESIZE 5
|
||||
#define FPS 60
|
||||
#define LEDLEVEL 8
|
||||
#define FPS 50
|
||||
#define LEDLEVEL 16
|
||||
|
||||
byte cube[CUBESIZE][CUBESIZE][CUBESIZE];
|
||||
|
||||
|
|
@ -54,6 +54,46 @@ void dimm_cube(int diff = -1) {
|
|||
}
|
||||
}
|
||||
|
||||
void cube_move_x(int diff) {
|
||||
diff = constrain(diff, -CUBESIZE, CUBESIZE);
|
||||
byte from;
|
||||
for (byte v = 0; v < CUBESIZE; v++) {
|
||||
from = (v + diff) % CUBESIZE;
|
||||
for (byte a = 0; a < CUBESIZE; a++) {
|
||||
for (byte b = 0; b < CUBESIZE; b++) {
|
||||
cube[v][a][b] = cube[from][a][b];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void cube_move_y(int diff) {
|
||||
diff = constrain(diff, -CUBESIZE, CUBESIZE);
|
||||
byte from;
|
||||
for (byte v = 0; v < CUBESIZE; v++) {
|
||||
from = (v + diff) % CUBESIZE;
|
||||
for (byte a = 0; a < CUBESIZE; a++) {
|
||||
for (byte b = 0; b < CUBESIZE; b++) {
|
||||
cube[a][v][b] = cube[a][from][b];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void cube_move_z(int diff) {
|
||||
diff = constrain(diff, -CUBESIZE, CUBESIZE);
|
||||
byte from;
|
||||
for (byte v = 0; v < CUBESIZE; v++) {
|
||||
from = (v + diff) % CUBESIZE;
|
||||
for (byte a = 0; a < CUBESIZE; a++) {
|
||||
for (byte b = 0; b < CUBESIZE; b++) {
|
||||
cube[a][b][v] = cube[a][b][from];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void cube_rotate_cover(int steps, unsigned int frame_delay = 100) {
|
||||
byte x = 0;
|
||||
byte y = 0;
|
||||
|
|
|
|||
|
|
@ -177,5 +177,161 @@ void cube_effect_dots(int duration = 0) {
|
|||
}
|
||||
}
|
||||
};
|
||||
void cube_life(int duration = 0) {
|
||||
int speed = 50;
|
||||
int value;
|
||||
int min = LEDLEVEL * 2;
|
||||
int max = LEDLEVEL * 4;
|
||||
|
||||
if (duration <= 0)
|
||||
duration = random(MIN_DURATION, MAX_DURATION);
|
||||
|
||||
// mit zufallsmuster füllen
|
||||
fill_cube(0);
|
||||
|
||||
for (byte x = 0; x < CUBESIZE; x++) {
|
||||
for (byte y = 0; y < CUBESIZE; y++) {
|
||||
for (byte z = 0; z < CUBESIZE; z++) {
|
||||
if (random(100) >= 50) {
|
||||
cube[x][y][z] = random(LEDLEVEL + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
effect_ende = millis() + duration * 1000;
|
||||
|
||||
while (millis() < effect_ende) {
|
||||
|
||||
for (byte x = 0; x < CUBESIZE; x++) {
|
||||
for (byte y = 0; y < CUBESIZE; y++) {
|
||||
for (byte z = 0; z < CUBESIZE; z++) {
|
||||
value = 0;
|
||||
value += cube[(x - 1) % CUBESIZE][y][z];
|
||||
value += cube[(x + 1) % CUBESIZE][y][z];
|
||||
value += cube[x][(y - 1) % CUBESIZE][z];
|
||||
value += cube[x][(y + 1) % CUBESIZE][z];
|
||||
value += cube[x][y][(z - 1) % CUBESIZE];
|
||||
value += cube[x][y][(z + 1) % CUBESIZE];
|
||||
if ((value < min) || (value >= max)) {
|
||||
if (cube[x][y][z] > 0) {
|
||||
cube[x][y][z]--;
|
||||
};
|
||||
|
||||
} else {
|
||||
if (cube[x][y][z] < LEDLEVEL) {
|
||||
cube[x][y][z]++;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delay(speed);
|
||||
}
|
||||
}
|
||||
|
||||
struct Dot {
|
||||
byte x;
|
||||
byte y;
|
||||
byte z;
|
||||
int vx;
|
||||
int vy;
|
||||
int vz;
|
||||
byte value;
|
||||
};
|
||||
|
||||
void cube_moving_dots(int duration = 0) {
|
||||
int speed = 100;
|
||||
int dotcount = 2;
|
||||
Dot dots[dotcount];
|
||||
//Dot dot;
|
||||
for (byte d = 0; d < dotcount; d++) {
|
||||
dots[d].x = random(CUBESIZE) * 10;
|
||||
dots[d].y = random(CUBESIZE) * 10;
|
||||
dots[d].z = random(CUBESIZE) * 10;
|
||||
dots[d].vx = random(20) - 10;
|
||||
dots[d].vy = random(20) - 10;
|
||||
dots[d].vz = random(20) - 10;
|
||||
dots[d].value = random(LEDLEVEL / 2, LEDLEVEL);
|
||||
}
|
||||
// Serial.println("cube: moving "+String(dotcount)+" dots");
|
||||
if (duration <= 0)
|
||||
duration = random(MIN_DURATION, MAX_DURATION);
|
||||
effect_ende = millis() + duration * 1000;
|
||||
|
||||
// mit zufallsmuster füllen
|
||||
fill_cube(0);
|
||||
while (millis() < effect_ende) {
|
||||
// dimm_cube(LEDLEVEL/-4);
|
||||
// fill_cube(0);
|
||||
for (byte d = 0; d < dotcount; d++) {
|
||||
|
||||
cube[dots[d].x / 10][dots[d].y / 10][dots[d].z / 10] = 0;
|
||||
|
||||
if (((dots[d].x + dots[d].vx) <= 0) ||
|
||||
((dots[d].x + dots[d].vx) >= CUBESIZE * 10))
|
||||
dots[d].vx = -dots[d].vx;
|
||||
if (((dots[d].y + dots[d].vy) <= 0) ||
|
||||
((dots[d].y + dots[d].vy) >= CUBESIZE * 10))
|
||||
dots[d].vy = -dots[d].vy;
|
||||
if (((dots[d].z + dots[d].vz) <= 0) ||
|
||||
((dots[d].z + dots[d].vz) >= CUBESIZE * 10))
|
||||
dots[d].vz = -dots[d].vz;
|
||||
|
||||
dots[d].x = (dots[d].x + dots[d].vx);
|
||||
dots[d].y = (dots[d].y + dots[d].vy);
|
||||
dots[d].z = (dots[d].z + dots[d].vz);
|
||||
|
||||
// Serial.println("Dot
|
||||
// ["+String(dot.x)+"]["+String(dot.y)+"]["+String(dot.z)+"] /
|
||||
// ["+String((int)dot.vx)+"]["+String((int)dot.vy)+"]["+String((int)dot.vz)+"]
|
||||
// = "+String(dot.value));
|
||||
cube[dots[d].x / 10][dots[d].y / 10][dots[d].z / 10] = dots[d].value;
|
||||
}
|
||||
|
||||
delay(speed);
|
||||
}
|
||||
}
|
||||
|
||||
void cube_shifting_layer(int duration = 0) {
|
||||
int speed = 50;
|
||||
int value,x,y;
|
||||
fill_cube(0);
|
||||
for (x = 0; x < CUBESIZE; x++) {
|
||||
for (y = 0; y < CUBESIZE; y++) {
|
||||
cube[x][y][0] = LEDLEVEL;
|
||||
}
|
||||
}
|
||||
|
||||
if (duration <= 0)
|
||||
duration = random(MIN_DURATION, MAX_DURATION);
|
||||
effect_ende = millis() + duration * 1000;
|
||||
|
||||
while (millis() < effect_ende) {
|
||||
value = random(4);
|
||||
|
||||
switch (value) {
|
||||
case 0:
|
||||
cube_move_x(1);
|
||||
break;
|
||||
case 1:
|
||||
cube_move_x(-1);
|
||||
break;
|
||||
case 2:
|
||||
cube_move_y(1);
|
||||
break;
|
||||
case 3:
|
||||
cube_move_y(-1);
|
||||
break;
|
||||
case 4:
|
||||
cube_move_z(1);
|
||||
break;
|
||||
case 5:
|
||||
cube_move_z(-1);
|
||||
break;
|
||||
}
|
||||
delay(speed);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
BIN
src/src/CubeEffects.h.gch
Normal file
BIN
src/src/CubeEffects.h.gch
Normal file
Binary file not shown.
BIN
src/src/CubeRegister.h.gch
Normal file
BIN
src/src/CubeRegister.h.gch
Normal file
Binary file not shown.
|
|
@ -115,7 +115,7 @@ void cube_text_warp(const char *message) {
|
|||
for (size_t mp = 0; mp < strlen(message); mp++) {
|
||||
int s = CUBESIZE - 1;
|
||||
for (int i = 0; i < (CUBESIZE + LEDLEVEL); i++) {
|
||||
dimm_cube(LEDLEVEL / -2);
|
||||
dimm_cube(LEDLEVEL / -4);
|
||||
write_char(message[mp], max(s, 0), LEDLEVEL);
|
||||
s--;
|
||||
delay(50);
|
||||
|
|
|
|||
|
|
@ -5,37 +5,45 @@
|
|||
#include "CubeTextEffects.h"
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
// Serial.begin(115200);
|
||||
init_cube();
|
||||
cube_startup();
|
||||
randomSeed(analogRead(A0) + analogRead(A1) + analogRead(A2));
|
||||
// cube_startup();
|
||||
}
|
||||
|
||||
// const char* messages = {"I°U", "mama ist die allerbeste!°!°", "benjamin",
|
||||
// "annika", "5x5x5 led-cube"};
|
||||
static const char *const messages[] = {"I°U", "mama ist die allerbeste!°!°",
|
||||
"benjamin", "annika", "5x5x5 led-cube"};
|
||||
//static const char *const messages[] = {"I°U", "mama ist die allerbeste!°!°",
|
||||
// "benjamin", "annika", "5x5x5 led-cube"};
|
||||
static const char *const messages[] = {"silvester", "2017>2018", "2018",
|
||||
"ohh, ahh", "led-cube"};
|
||||
|
||||
int message_count = 5;
|
||||
|
||||
void loop() {
|
||||
|
||||
|
||||
// int next_duration = random(10, 20);
|
||||
switch (random(0, 10)) {
|
||||
//switch (9) {
|
||||
switch (random(20)) {
|
||||
case 0:
|
||||
cube_effect_glow();
|
||||
break;
|
||||
case 1:
|
||||
cube_effect_glitzer();
|
||||
cube_effect_glitzer_fade();
|
||||
break;
|
||||
case 2:
|
||||
cube_effect_glitzer_levels();
|
||||
break;
|
||||
case 3:
|
||||
cube_effect_glitzer_fade();
|
||||
cube_effect_glitzer();
|
||||
break;
|
||||
case 4:
|
||||
cube_effect_dots();
|
||||
break;
|
||||
case 5:
|
||||
cube_startup();
|
||||
//cube_startup();
|
||||
cube_effect_glitzer_levels();
|
||||
break;
|
||||
case 6:
|
||||
cube_text_banner(messages[random(message_count)]);
|
||||
|
|
@ -43,6 +51,13 @@ void loop() {
|
|||
case 7:
|
||||
cube_text_warp(messages[random(message_count)]);
|
||||
break;
|
||||
case 8:
|
||||
cube_life();
|
||||
break;
|
||||
case 9:
|
||||
// Serial.println("cube_moving_dots");
|
||||
cube_moving_dots();
|
||||
break;
|
||||
/*
|
||||
case 8:
|
||||
if (random(10) > 5)
|
||||
|
|
|
|||
Loading…
Reference in a new issue