jediemil 4 anos atrás
pai
commit
183abd5ea8

+ 1 - 1
LedThing.ino/AnimationSetups.ino

@@ -5,11 +5,11 @@
 //4: table
 //5: var_1
 //6: i
-//7: lastAnimationMillis
 
 void setup_rainbow(int currentStripDiv) {
   normal_setup(currentStripDiv);
   current_animation_table[currentStripDiv][5] = 5.12;
+  Serial.println(currentStripDiv);
 }
 
 void normal_setup(int currentStripDiv) {

+ 74 - 20
LedThing.ino/Animations.ino

@@ -5,10 +5,21 @@
 //4: table
 //5: var_1
 //6: i
-//7: lastAnimationMillis
 
-int getVariables(int stripDiv) {
-  return current_animation_table[stripDiv][1], current_animation_table[stripDiv][2], current_animation_table[stripDiv][6], current_animation_table[stripDiv][5];
+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) {
@@ -16,28 +27,48 @@ void saveAnimI(int animI, int stripDiv) {
 }
 
 void animation_rainbow(int stripDiv) {
-  int numLeds, offset, animI, animVar1 = getVariables(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();
+  //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");
-  int numLeds, offset, animI, animVar1 = getVariables(stripDiv);
-  leds[animI] = CRGB(100, 255, 200);
-  FastLED.show();
+  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 (animation_i >= numLeds) {
+  if (animI >= numLeds) {
     animI = 0;
     clear_strip(stripDiv);
   }
@@ -46,7 +77,12 @@ void animation_running(int stripDiv) {
 
 void animation_chasing(int stripDiv) {
   //Serial.println("Animation 2 step");
-  int numLeds, offset, animI, animVar1 = getVariables(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);
   leds[animI] = CRGB(100, 255, 200);
   leds[((animI + 10) % numLeds) + offset] = CRGB(100, 255, 200);
@@ -64,19 +100,27 @@ void animation_chasing(int stripDiv) {
 //  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();
+  //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) {
-  int numLeds, offset, animI, animVar1 = getVariables(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++) {
@@ -136,16 +180,21 @@ void animation_random1(int stripDiv) {
       leds[currentStep + i * difference + offset] = CRGB(r, g, b);
     }
   }
-  FastLED.show();
+  //FastLED.show();
 }
 
 void animation_rgb_light(int stripDiv) {
-  int numLeds, offset, animI, animVar1 = getVariables(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 + animation_i) % numLeds] = CRGB(255, 0, 0);
-    leds[(i + animation_i + numLeds / 3) % numLeds] = CRGB(0, 255, 0);
-    leds[(i + animation_i + (numLeds / 3) * 2) % numLeds] = CRGB(0, 0, 255);
+    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;
@@ -161,14 +210,19 @@ void animation_rgb_light(int stripDiv) {
   //    b = (0 - 255) * i / 25 + 255;
   //    leds[(i + animation_i + 25 + 100) % NUM_LEDS] = CRGB(r, g, b);
   //  }
-  FastLED.show();
+  //FastLED.show();
   animI++;
   animI %= numLeds;
   saveAnimI(animI, stripDiv);
 }
 
 void animation_random2(int stripDiv) {
-  int numLeds, offset, animI, animVar1 = getVariables(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++) {
@@ -222,5 +276,5 @@ void animation_random2(int stripDiv) {
   //      }
   //    }
   //  }
-  FastLED.show();
+  //FastLED.show();
 }

+ 43 - 17
LedThing.ino/LedThing.ino.ino

@@ -13,20 +13,21 @@ char ssid[] = "Våfflan";
 char pass[] = "HemmaIoT";
 boolean doing_animation = true;
 
-int current_animation = 0;
-int current_animation_1 = 0;
+//int current_animation = 0;
+//int current_animation_1 = 0;
 int loops_since_http = 0;
 
-int animation_step_time = 0;
-int animation_i = 0;
-int animation_var_1 = 0;
+//int animation_step_time = 0;
+//int animation_i = 0;
+//int animation_var_1 = 0;
 int animation_table_1[2][10][8] = {};
 int number_of_splits = 2;
 
 long last_animation_millis = millis();
 long latest_animation_change = millis();
 
-int current_animation_table[2][8]; //animation_number, NUM_LEDS, led_offset, speed, table, var_1, i, lastAnimationMillis;
+int current_animation_table[2][7]; //animation_number, NUM_LEDS, led_offset, speed, table, var_1, i;
+long animation_millis[2];
 
 bool split_animations = false;
 
@@ -59,8 +60,11 @@ void setup() {
   current_animation_table[0][0] = 0;
   current_animation_table[0][1] = 150;
   current_animation_table[0][2] = 0;
+  current_animation_table[1][0] = 0;
   current_animation_table[1][1] = 50;
   current_animation_table[1][2] = 150;
+  animation_millis[0] = millis();
+  animation_millis[1] = millis();
   setup_random1(0);
   // put your setup code here, to run once:
   //Serial.begin(9600);
@@ -71,7 +75,7 @@ void setup() {
   Serial.println("Starting");
 
   FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS_WS).setCorrection( TypicalLEDStrip ); //TM1804 BRG //WS2812 GRB
-  FastLED.addLeds<TM1804, DATA_PIN_2, BRG>(leds, NUM_LEDS_TM).setCorrection( TypicalLEDStrip ); //TM1804 BRG //WS2812 GRB
+  FastLED.addLeds<TM1804, DATA_PIN_2, BRG>(leds, NUM_LEDS_WS, NUM_LEDS_TM).setCorrection( TypicalLEDStrip ); //TM1804 BRG //WS2812 GRB
   FastLED.setBrightness(255);
   FastLED.clear();
   FastLED.show();
@@ -134,20 +138,37 @@ void setup() {
   //    }
   //  }
   delay(1000);
-  current_animation = 0;
-  setup_table[current_animation](0);
+  //current_animation = 0;
+  setup_table[0](0);
+  setup_table[0](1);
   Serial.println("Started");
 }
 
 void loop() {
   loops_since_http += 1;
   if (loops_since_http < 100) {
+    //Serial.println("In loop123123");
+    long current_millis = millis();
+    bool doneAnimationStep = false;
     for (int i = 0; i < number_of_splits; i++) {
-      long current_millis = millis();
-      if (current_millis - current_animation_table[i][7] >= animation_step_time) {
-        animation_table[current_animation_table[i][1]](i);
-        current_animation_table[i][7] = current_millis;
+      //Serial.println("In loop-1");
+      //Serial.println(i);
+      if (current_millis - animation_millis[i] >= current_animation_table[i][3]) {
+        doneAnimationStep = true;
+        //Serial.println("A");
+        //current_animation_table[i][1] = 1;
+        animation_table[current_animation_table[i][0]](i);
+//        Serial.println(current_animation_table[0][0]);
+//        Serial.println(current_animation_table[1][0]);
+        animation_millis[i] = current_millis;
+        //Serial.println("After loop");
       }
+      //Serial.println("In loop-3");
+    }
+    if (doneAnimationStep) {
+      FastLED.show();
+      Serial.println(leds[170]);
+      Serial.println(leds[100]);
     }
   
 //    if (doing_animation) {
@@ -160,6 +181,7 @@ void loop() {
 //      }
 //    }
 //    last_animation_millis = current_millis;
+    //Serial.println("idle");
   
   } else {
     loops_since_http = 0;
@@ -211,8 +233,8 @@ void process_HTTP() {
     int currentLoop = 0;
     int setting = 0;
     int value = 0;
-    int modify_animation = current_animation_table[1][0];
-    byte current_strip_half = 0;
+    int modify_animation = current_animation_table[0][0];
+    int current_strip_half = 0;
     String fullArguments = "";
     while (client.connected()) {
       if (client.available()) {
@@ -276,10 +298,11 @@ void process_HTTP() {
           if (c == '0' || c == '1') {
             readingState = 1;
             split_animations = true;
-            current_strip_half = (byte) c;
+            current_strip_half = String(c).toInt();
             if (c == '1') {
               modify_animation = current_animation_table[1][0];
             }
+            continue;
           } else {
             split_animations = false;
           }
@@ -327,6 +350,9 @@ void process_HTTP() {
       setup_table[anim](current_strip_half);
       current_animation_table[current_strip_half][0] = anim;
       latest_animation_change = millis();
+      Serial.println(current_strip_half);
+      Serial.println(current_animation_table[current_strip_half][0]);
+      Serial.println(anim);
 
     } else if (readingState == 3) {
       Serial.println(setting);
@@ -355,7 +381,7 @@ void clear_strip(int stripDiv) {
   for (int i = 0; i < current_animation_table[stripDiv][1]; i++) {
     leds[i + current_animation_table[stripDiv][2]] = CRGB(0, 0, 0);
   }
-  FastLED.show();
+  //FastLED.show();
 }
 
 void animation_fade_help() {//TODO MAKE WORKABLE FOR SPLIT STRIP-------------------------------------------------------------------------------------------------------------------------------------------------------------