| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- //0: animation_number
- //1: NUM_LEDS
- //2: led_offset
- //3: speed
- //4: table
- //5: var_1
- //6: i
- struct variables {
- int numLeds;
- int offset;
- int animI;
- int animVar1;
- };
- struct variables getVariables(int stripDiv) {
- struct variables myVariables;
- myVariables.numLeds = current_animation_table[stripDiv][1];
- myVariables.offset = current_animation_table[stripDiv][2];
- myVariables.animI = current_animation_table[stripDiv][6];
- myVariables.animVar1 = current_animation_table[stripDiv][5];
- return myVariables;
- }
- void saveAnimI(int animI, int stripDiv) {
- current_animation_table[stripDiv][6] = animI;
- }
- void animation_rainbow(int stripDiv) {
- struct variables animVariables = getVariables(stripDiv);
- int numLeds = animVariables.numLeds;
- int offset = animVariables.offset;
- int animI = animVariables.animI;
- int animVar1 = animVariables.animVar1;
-
- int h = animI;
- for (int i = 0; i < numLeds; i++) {
- h = (h + animVar1) % 256;
- leds[i + offset] = CHSV(h, 255, 255);
- }
- //fill_rainbow(leds, NUM_LEDS, animation_i, animation_var_1);
- //FastLED.show()
- animI++;
- animI %= 256;
- saveAnimI(animI, stripDiv);
- // Serial.println("Rainbow");
- // Serial.println(stripDiv);
- Serial.println(numLeds);
- Serial.println(offset);
- // Serial.println(animVar1);
- // Serial.println(animI);
- // Serial.println(current_animation_table[1][2]);
- // Serial.println(current_animation_table[stripDiv][2]);
- //Serial.println(animation_i);
- //Serial.println("Animation 1 step");
- }
- void animation_running(int stripDiv) {
- //Serial.println("Animation 2 step");
- struct variables animVariables = getVariables(stripDiv);
- int numLeds = animVariables.numLeds;
- int offset = animVariables.offset;
- int animI = animVariables.animI;
- int animVar1 = animVariables.animVar1;
- Serial.println(animI + offset);
-
- leds[animI + offset] = CRGB(100, 255, 200);
- //FastLED.show();
- animI++;
- if (animI >= numLeds) {
- animI = 0;
- clear_strip(stripDiv);
- }
- saveAnimI(animI, stripDiv);
- }
- void animation_chasing(int stripDiv) {
- //Serial.println("Animation 2 step");
- struct variables animVariables = getVariables(stripDiv);
- int numLeds = animVariables.numLeds;
- int offset = animVariables.offset;
- int animI = animVariables.animI;
- int animVar1 = animVariables.animVar1;
-
- clear_strip(stripDiv);
- leds[animI] = CRGB(100, 255, 200);
- leds[((animI + 10) % numLeds) + offset] = CRGB(100, 255, 200);
- leds[((animI + 20) % numLeds) + offset] = CRGB(100, 255, 200);
- leds[((numLeds) - animI) - 1 + offset] = CRGB(0, 255, 255);
- // leds[animation_i * 3 + 1] = CRGB(100, 255, 200);
- // leds[(animation_i * 3 + 1 + 10 * 3) % (NUMBER_OF_LEDS)] = CRGB(100, 255, 200);
- // leds[(animation_i * 3 + 1 + 20 * 3) % (NUMBER_OF_LEDS)] = CRGB(100, 255, 200);
- // leds[((NUMBER_OF_LEDS) - animation_i * 3 + 1) - 1 * 3] = CRGB(0, 255, 255);
- //
- // leds[animation_i * 3 + 2] = CRGB(100, 255, 200);
- // leds[(animation_i * 3 + 2 + 10 * 3) % (NUMBER_OF_LEDS)] = CRGB(100, 255, 200);
- // leds[(animation_i * 3 + 2 + 20 * 3) % (NUMBER_OF_LEDS)] = CRGB(100, 255, 200);
- // leds[((NUMBER_OF_LEDS) - animation_i * 3 + 2) - 1 * 3] = CRGB(0, 255, 255);
- // leds[(50 - animation_i - 10)] = CRGB(0, 255, 255);
- // leds[(50 - animation_i)] = CRGB(0, 255, 255);
- //FastLED.show();
- animI++;
- animI %= numLeds;
- saveAnimI(animI, stripDiv);
- }
- void animation_off(int stripDiv) {
- //Serial.println("animation off");
- clear_strip(stripDiv);
- //Serial.println("animation off 2");
- current_animation_table[stripDiv][3] = 10000;
- //Serial.println("animation off 3");
- }
- void animation_random1(int stripDiv) {
- struct variables animVariables = getVariables(stripDiv);
- int numLeds = animVariables.numLeds;
- int offset = animVariables.offset;
- int animI = animVariables.animI;
- int animVar1 = animVariables.animVar1;
-
- int difference = numLeds / animVar1;
- for (int i = 0; i < animVar1; i++) {
- int howManyCycles = animation_table_1[stripDiv][i][7];
- int currentStep = animation_table_1[stripDiv][i][6];
- uint8_t startRed = animation_table_1[stripDiv][i][0];
- uint8_t startGreen = animation_table_1[stripDiv][i][1];
- uint8_t startBlue = animation_table_1[stripDiv][i][2];
- uint8_t goalRed = animation_table_1[stripDiv][i][3];
- uint8_t goalGreen = animation_table_1[stripDiv][i][4];
- uint8_t goalBlue = animation_table_1[stripDiv][i][5];
- uint8_t r = (goalRed - startRed) * currentStep / howManyCycles + startRed;
- uint8_t g = (goalGreen - startGreen) * currentStep / howManyCycles + startGreen;
- uint8_t b = (goalBlue - startBlue) * currentStep / howManyCycles + startBlue;
- // for (int led = 0; led < 10; led++) {
- // leds[led + i * 10] = CRGB(r, b, g);
- // }
- leds[i * difference + offset] = CRGB(r, b, g);
- animation_table_1[stripDiv][i][6] += 1;
- if (currentStep >= howManyCycles) {
- // uint8_t newR = (uint8_t) random(0, 255);
- // uint8_t newG = (uint8_t) random(0, 255);
- // uint8_t newB = (uint8_t) random(0, 255);
- uint8_t newH = (uint8_t) random(0, 255);
- uint8_t newS = (uint8_t) random(200, 255);
- CRGB newColor = CRGB(0, 0, 0);
- newColor.setHSV(newH, newS, 255);
- animation_table_1[stripDiv][i][3] = newColor.r;
- animation_table_1[stripDiv][i][4] = newColor.g;
- animation_table_1[stripDiv][i][5] = newColor.b;
- uint8_t steps = (uint8_t) random(50, 255);
- animation_table_1[stripDiv][i][0] = r;
- animation_table_1[stripDiv][i][1] = g;
- animation_table_1[stripDiv][i][2] = b;
- animation_table_1[stripDiv][i][7] = steps;
- animation_table_1[stripDiv][i][6] = 0;
- }
- }
- for (int i = 0; i < animVar1; i++) {
- uint8_t startRed = leds[i * difference + offset].r;
- uint8_t startGreen = leds[i * difference + offset].g;
- uint8_t startBlue = leds[i * difference + offset].b;
- uint8_t goalRed = leds[((i + 1) * difference) % numLeds + offset].r;
- uint8_t goalGreen = leds[((i + 1) * difference) % numLeds + offset].g;
- uint8_t goalBlue = leds[((i + 1) * difference) % numLeds + offset].b;
- for (int currentStep = 1; currentStep < difference; currentStep++) {
- uint8_t r = (goalRed - startRed) * currentStep / difference + startRed;
- uint8_t g = (goalGreen - startGreen) * currentStep / difference + startGreen;
- uint8_t b = (goalBlue - startBlue) * currentStep / difference + startBlue;
- leds[currentStep + i * difference + offset] = CRGB(r, g, b);
- }
- }
- //FastLED.show();
- }
- void animation_rgb_light(int stripDiv) {
- struct variables animVariables = getVariables(stripDiv);
- int numLeds = animVariables.numLeds;
- int offset = animVariables.offset;
- int animI = animVariables.animI;
- int animVar1 = animVariables.animVar1;
-
- clear_strip(stripDiv);
- for (int i = offset; i < (numLeds + offset) / 6; i++) {
- leds[(i + animI) % numLeds] = CRGB(255, 0, 0);
- leds[(i + animI + numLeds / 3) % numLeds] = CRGB(0, 255, 0);
- leds[(i + animI + (numLeds / 3) * 2) % numLeds] = CRGB(0, 0, 255);
- }
- // for (int i = 1; i < NUM_LEDS/6; i++) { // Made an animation that already exists, but more complicated (animation_rainbow)
- // uint8_t r = (0 - 255) * i / 25 + 255;
- // uint8_t g = (255) * i / 25;
- // uint8_t b = 0;
- // leds[(i + animation_i + 25) % NUM_LEDS] = CRGB(r, g, b);
- // r = 0;
- // g = (0 - 255) * i / 25 + 255;
- // b = (255) * i / 25;
- // leds[(i + animation_i + 25 + 50) % NUM_LEDS] = CRGB(r, g, b);
- // r = (255 - 0) * i / 25 + 0;
- // g = 0;
- // b = (0 - 255) * i / 25 + 255;
- // leds[(i + animation_i + 25 + 100) % NUM_LEDS] = CRGB(r, g, b);
- // }
- //FastLED.show();
- animI++;
- animI %= numLeds;
- saveAnimI(animI, stripDiv);
- }
- void animation_random2(int stripDiv) {
- struct variables animVariables = getVariables(stripDiv);
- int numLeds = animVariables.numLeds;
- int offset = animVariables.offset;
- int animI = animVariables.animI;
- int animVar1 = animVariables.animVar1;
-
- if (random(0, animVar1) == 0) {
- //Serial.println("Stage 1");
- for (int i = 0; i < 10; i++) {
- //Serial.println("Stage 2");
- //Serial.println(animation_table_1[i][1]);
- if (animation_table_1[stripDiv][i][1] == 0) {
- //Serial.println("Stage 3");
- int randomDot = random(0, numLeds);
- //Serial.println(randomDot);
- if (!leds[randomDot]) {
- //Serial.println("Stage 4");
- animation_table_1[stripDiv][i][0] = random(0, 255);
- animation_table_1[stripDiv][i][1] = 255;
- animation_table_1[stripDiv][i][2] = randomDot;
- animation_table_1[stripDiv][i][3] = 1;
- //Serial.println(animation_table_1[i][0]);
- leds[randomDot + offset] = CHSV(animation_table_1[stripDiv][i][0], 255, 126);
- break;
- }
- }
- }
- }
- for (int i = 0; i < 10; i++) {
- if (animation_table_1[stripDiv][i][3] == 1) {
- leds[animation_table_1[stripDiv][i][2] + offset] = CHSV(animation_table_1[stripDiv][i][0], 255, 126);
- animation_table_1[stripDiv][i][3] = 2;
- } else if (animation_table_1[stripDiv][i][3] == 2) {
- leds[animation_table_1[stripDiv][i][2] + offset] = CHSV(animation_table_1[stripDiv][i][0], 255, 255);
- animation_table_1[stripDiv][i][3] = 0;
- } else {
- animation_table_1[stripDiv][i][1] = max(animation_table_1[stripDiv][i][1] - 10, 0);
- leds[animation_table_1[stripDiv][i][2] + offset] = CHSV(animation_table_1[stripDiv][i][0], 255, animation_table_1[stripDiv][i][1]);
- }
- }
- // if (animation_i <= animation_var_1) {
- // int randomDot = random(0, NUMBER_OF_LEDS);
- // if (!leds[randomDot]) {
- // leds[randomDot] = CHSV(random(0, 255), 255, 255);
- // animation_i += 1;
- // }
- // } else {
- // for (int i = 0; i < NUM_LEDS; i++) {
- // if (leds[i]) {
- // if (random(1, animation_var_1) == 1) {
- // leds[i] = CRGB(0, 0, 0);
- // animation_i -= 1;
- // }
- // }
- // }
- // }
- //FastLED.show();
- }
|