Quellcode durchsuchen

Fully working. WiFi and SD not tested yet

Emil vor 3 Jahren
Ursprung
Commit
00ad96124c
4 geänderte Dateien mit 51 neuen und 42 gelöschten Zeilen
  1. 14 14
      src/Animations.cpp
  2. 20 20
      src/LightCluster.cpp
  3. 1 1
      src/LightCluster.h
  4. 16 7
      src/main.cpp

+ 14 - 14
src/Animations.cpp

@@ -5,11 +5,11 @@
 #include "Animations.h"
 
 Animations::Animations(struct light *lights) {
-    Serial.println("Inside animations constructor");
-    delay(100);
+    //Serial.println("Inside animations constructor");
+    //delay(100);
     this->lights = lights;
-    Serial.println("Animations constructed");
-    delay(100);
+    //Serial.println("Animations constructed");
+    //delay(100);
 }
 
 /*void Animations::createLookup() {
@@ -20,20 +20,20 @@ Animations::Animations(struct light *lights) {
 }*/
 
 void Animations::runAnimation(int animationID) {
-    /*Serial.println("Sketchy function call");
-    delay(100);
+    //Serial.println("Sketchy function call");
+    //delay(100);
     method_function func = animationPointer[animationID];
     (this->*func)();
-    Serial.println("Animation call success");
-    delay(100);*/
+    //Serial.println("Animation call success");
+    //delay(100);
 
-    if (animationID == 0) {
-        this->rainbow();
-    }
+    //if (animationID == 0) {
+    //    this->rainbow();
+    //}
 }
 
 void Animations::runSetup(int animationID) {
-    Serial.println("Inside setup");
+    //Serial.println("Inside setup");
     method_function func = setupPointer[animationID];
     (this->*func)();
     //if (animationID == 0) {
@@ -42,8 +42,8 @@ void Animations::runSetup(int animationID) {
 }
 
 void Animations::rainbow() {
-    Serial.println("Inside animation function");
-    delay(100);
+    //Serial.println("Inside animation function");
+    //delay(100);
     for (int light = 0; light < numLeds; light++) {
         lights[light].color = leds.ColorHSV(((light * animationSetting1 + animationI*65536/maxAnimationI) % 65536), 255, 255);
 //        Serial.print("Set ");

+ 20 - 20
src/LightCluster.cpp

@@ -5,35 +5,35 @@
 #include "LightCluster.h"
 #include "main.h"
 
-void LightCluster::runAnimation() {
+bool LightCluster::runAnimation() {
     if (shouldRun()) {
-        Serial.println("Animation begin");
-        delay(100);
+        //Serial.println("Animation begin");
+        //delay(100);
         animationObject->runAnimation(animationNumber);
         lastRun = millis();
 
-        Serial.println("Animation call success, setting colors");
-        Serial.println(animationObject->numLeds);
-        delay(100);
+        //Serial.println("Animation call success, setting colors");
+        //Serial.println(animationObject->numLeds);
+        //delay(100);
         for (int i = 0; i < animationObject->numLeds; i++) {
-            Serial.print("lights mapped = ");
+            /*Serial.print("lights mapped = ");
             Serial.println(animationObject->lights[i].mapped);
             Serial.print("color = ");
-            Serial.println(animationObject->lights[i].color, HEX);
+            Serial.println(animationObject->lights[i].color, HEX);*/
             leds.setPixelColor(animationObject->lights[i].mapped, animationObject->lights[i].color);
         }
-        Serial.println("Colors set");
-        delay(100);
+        //Serial.println("Colors set");
+        //delay(100);
         //Serial.println("Animation has run");
-        //return true;
+        return true;
     }
-    //return false;
+    return false;
 }
 
 void LightCluster::runSetup() {
-    Serial.println("Before setup");
+    //Serial.println("Before setup");
     animationObject->runSetup(animationNumber);
-    Serial.println("After setup");
+    //Serial.println("After setup");
 }
 
 void LightCluster::changeAnimation(int newAnimationNumber) {
@@ -49,19 +49,19 @@ LightCluster::LightCluster(struct light *incomingLights, int size, int animation
 //        data.mapped = lights[i];
 //        this->lights[i] = data;
 //    }
-    Serial.println("Inside light cluster constructor");
+    //Serial.println("Inside light cluster constructor");
     animationNumber = animation;
     numLights = size;
     animationObject->numLeds = size;
     lastRun = 0;
-    Serial.println("About to set up animation object");
+    //Serial.println("About to set up animation object");
     this->animationObject = animationObject;
-    Serial.println("Creating lookup");
+    //Serial.println("Creating lookup");
     //this->animationObject.createLookup();
-    Serial.println("Construct done, running setup and animation");
+    //Serial.println("Construct done, running setup and animation");
     runSetup();
-    Serial.println("Running animation");
-    delay(100);
+    //Serial.println("Running animation");
+    //delay(100);
     runAnimation();
 }
 

+ 1 - 1
src/LightCluster.h

@@ -20,7 +20,7 @@ public:
     int numLights;
     int animationNumber;
 
-    void runAnimation();
+    bool runAnimation();
     void changeAnimation(int newAnimationNumber);
 
     LightCluster(struct light *incomingLights, int size, int animation, Animations *animationObject);

+ 16 - 7
src/main.cpp

@@ -22,6 +22,10 @@ light lampsInCluster1[7] = {{0,0},{1,0},{3,0},{4,0},{5,0},{6,0},{7,0}};
 Animations animation1(lampsInCluster1);
 LightCluster myCluster(lampsInCluster1, 7, 0, &animation1);
 
+light lampsInCluster2[2] = {{2,0},{8,0}};
+Animations animation2(lampsInCluster2);
+LightCluster myCluster2(lampsInCluster2, 2, 0, &animation2);
+
 
 //LightCluster myCluster(lampsInCluster1, 7, 0, Animations(lampsInCluster1));
 
@@ -78,6 +82,8 @@ void setup() {
     // write your initialization code here
     Serial.begin(115000);
     clusters[0] = &myCluster;
+    myCluster2.animationObject->delayTimeMS = 10;
+    clusters[1] = &myCluster2;
     /*connectSDCard();
     Serial.println("\nSD card connected. Connecting WiFi\n");
     delay(250);
@@ -156,15 +162,18 @@ void loop() {
         }
     }
     //myCluster.runAnimation();
-    clusters[0]->runAnimation();
-    Serial.println("Animation has done 1 loop step, showing leds");
-    delay(10);
-    for (int i = 0; i < NUM_LEDS; i++) {
+    bool hasRun = clusters[0]->runAnimation() || clusters[1]->runAnimation();
+    //clusters[1]->runAnimation();
+    //Serial.println("Animation has done 1 loop step, showing leds");
+    //delay(10);
+    /*for (int i = 0; i < NUM_LEDS; i++) {
         Serial.println(leds.getPixelColor(i));
         delay(10);
+    }*/
+    if (hasRun) {
+        leds.show();
     }
-    leds.show();
 
-    Serial.println("Leds showed");
-    delay(10);
+    //Serial.println("Leds showed");
+    delay(1);
 }