Jelajahi Sumber

Working and diplaying stuff

Emil 3 tahun lalu
induk
melakukan
402ac33142
5 mengubah file dengan 51 tambahan dan 22 penghapusan
  1. 2 1
      platformio.ini
  2. 9 3
      src/Animations.cpp
  3. 20 11
      src/LightCluster.cpp
  4. 2 2
      src/LightCluster.h
  5. 18 5
      src/main.cpp

+ 2 - 1
platformio.ini

@@ -15,4 +15,5 @@ framework = arduino
 lib_deps =
 	me-no-dev/AsyncTCP@^1.1.1
 	me-no-dev/ESP Async WebServer
-	adafruit/Adafruit NeoPixel@^1.10.4
+	adafruit/Adafruit NeoPixel@^1.10.4
+	;FastLED/FastLED

+ 9 - 3
src/Animations.cpp

@@ -20,12 +20,16 @@ Animations::Animations(struct light *lights) {
 }*/
 
 void Animations::runAnimation(int animationID) {
+    /*Serial.println("Sketchy function call");
+    delay(100);
     method_function func = animationPointer[animationID];
     (this->*func)();
+    Serial.println("Animation call success");
+    delay(100);*/
 
-    //if (animationID == 0) {
-    //    rainbow();
-    //}
+    if (animationID == 0) {
+        this->rainbow();
+    }
 }
 
 void Animations::runSetup(int animationID) {
@@ -38,6 +42,8 @@ void Animations::runSetup(int animationID) {
 }
 
 void Animations::rainbow() {
+    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 - 11
src/LightCluster.cpp

@@ -7,17 +7,23 @@
 
 void LightCluster::runAnimation() {
     if (shouldRun()) {
-        //Serial.println("Animation begin");
-        animationObject.runAnimation(animationNumber);
+        Serial.println("Animation begin");
+        delay(100);
+        animationObject->runAnimation(animationNumber);
         lastRun = millis();
 
-        for (int i = 0; i < numLights; i++) {
-//            Serial.print("lights mapped = ");
-//            Serial.println(lights[i].mapped);
-//            Serial.print("color = ");
-//            Serial.println(lights[i].color, HEX);
-            leds.setPixelColor(animationObject.lights[i].mapped, animationObject.lights[i].color);
+        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.println(animationObject->lights[i].mapped);
+            Serial.print("color = ");
+            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("Animation has run");
         //return true;
     }
@@ -26,7 +32,7 @@ void LightCluster::runAnimation() {
 
 void LightCluster::runSetup() {
     Serial.println("Before setup");
-    animationObject.runSetup(animationNumber);
+    animationObject->runSetup(animationNumber);
     Serial.println("After setup");
 }
 
@@ -36,7 +42,7 @@ void LightCluster::changeAnimation(int newAnimationNumber) {
     runAnimation();
 }
 
-LightCluster::LightCluster(struct light *incomingLights, int size, int animation, Animations animationObject)
+LightCluster::LightCluster(struct light *incomingLights, int size, int animation, Animations *animationObject)
         : animationObject(animationObject) {
 //    for (int i = 0; i < sizeof(lights); i++) {
 //        light data;
@@ -46,6 +52,7 @@ LightCluster::LightCluster(struct light *incomingLights, int size, int animation
     Serial.println("Inside light cluster constructor");
     animationNumber = animation;
     numLights = size;
+    animationObject->numLeds = size;
     lastRun = 0;
     Serial.println("About to set up animation object");
     this->animationObject = animationObject;
@@ -53,12 +60,14 @@ LightCluster::LightCluster(struct light *incomingLights, int size, int animation
     //this->animationObject.createLookup();
     Serial.println("Construct done, running setup and animation");
     runSetup();
+    Serial.println("Running animation");
+    delay(100);
     runAnimation();
 }
 
 bool LightCluster::shouldRun() {
     //Serial.println("ShouldRun started");
-    if (millis() - lastRun >= animationObject.delayTimeMS) {
+    if (millis() - lastRun >= animationObject->delayTimeMS) {
         //Serial.println("ShouldRun true");
         return true;
     }

+ 2 - 2
src/LightCluster.h

@@ -23,9 +23,9 @@ public:
     void runAnimation();
     void changeAnimation(int newAnimationNumber);
 
-    LightCluster(struct light *incomingLights, int size, int animation, Animations animationObject);
+    LightCluster(struct light *incomingLights, int size, int animation, Animations *animationObject);
 
-    Animations animationObject;
+    Animations *animationObject;
 };
 
 

+ 18 - 5
src/main.cpp

@@ -17,10 +17,13 @@ AsyncWebServer server(80);
 
 Adafruit_NeoPixel leds(NUM_LEDS, LED_PIN, NEO_WRGB + NEO_KHZ800);
 
-//LightCluster clusters[] = {};
+LightCluster *clusters[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);
 
-LightCluster myCluster(lampsInCluster1, 7, 0, Animations(lampsInCluster1));
+
+//LightCluster myCluster(lampsInCluster1, 7, 0, Animations(lampsInCluster1));
 
 void connectWiFi() {
     WiFi.mode(WIFI_STA);
@@ -74,7 +77,7 @@ void setupServer() {
 void setup() {
     // write your initialization code here
     Serial.begin(115000);
-
+    clusters[0] = &myCluster;
     /*connectSDCard();
     Serial.println("\nSD card connected. Connecting WiFi\n");
     delay(250);
@@ -103,6 +106,7 @@ void setup() {
     //int lampsInCluster1[] = {0,1,2,3,4,5,6,7,8,9};
     //LightCluster mycluserr(lampsInCluster1, 0, 0);
     //clusters[0] = LightCluster(lampsInCluster1, 0, 0);
+
     Serial.println("Cluster made");
 
     delay(250);
@@ -151,7 +155,16 @@ void loop() {
             // do something else
         }
     }
-    myCluster.runAnimation();
+    //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++) {
+        Serial.println(leds.getPixelColor(i));
+        delay(10);
+    }
     leds.show();
-    delay(1);
+
+    Serial.println("Leds showed");
+    delay(10);
 }