|
@@ -4,7 +4,7 @@
|
|
|
|
|
|
|
|
#define NUM_LEDS 50
|
|
#define NUM_LEDS 50
|
|
|
#define DATA_PIN 9
|
|
#define DATA_PIN 9
|
|
|
-int NUMBER_OF_ANIMATIONS = 3;
|
|
|
|
|
|
|
+int NUMBER_OF_ANIMATIONS = 5;
|
|
|
char ssid[] = "Pannkakshuset";
|
|
char ssid[] = "Pannkakshuset";
|
|
|
char pass[] = "lavalampa";
|
|
char pass[] = "lavalampa";
|
|
|
|
|
|
|
@@ -14,21 +14,26 @@ int loops_since_http = 0;
|
|
|
int animation_step_time = 0;
|
|
int animation_step_time = 0;
|
|
|
int animation_i = 0;
|
|
int animation_i = 0;
|
|
|
int animation_var_1 = 0;
|
|
int animation_var_1 = 0;
|
|
|
|
|
+uint8_t animation_table_1[10][8] = {};
|
|
|
|
|
|
|
|
long last_animation_millis = millis();
|
|
long last_animation_millis = millis();
|
|
|
|
|
+long latest_animation_change = millis();
|
|
|
|
|
|
|
|
//typedef enum {STATE_A = 0, STATE_B = 1} State_type;
|
|
//typedef enum {STATE_A = 0, STATE_B = 1} State_type;
|
|
|
extern void animation_rainbow(); // forward declaration
|
|
extern void animation_rainbow(); // forward declaration
|
|
|
extern void animation_running(); // forward declaration
|
|
extern void animation_running(); // forward declaration
|
|
|
extern void animation_chasing();
|
|
extern void animation_chasing();
|
|
|
|
|
+extern void animation_off();
|
|
|
|
|
+extern void animation_random1();
|
|
|
|
|
|
|
|
-void (*animation_table[])() = {animation_rainbow, animation_running, animation_chasing};
|
|
|
|
|
|
|
+void (*animation_table[])() = {animation_off, animation_rainbow, animation_running, animation_chasing, animation_random1};
|
|
|
|
|
|
|
|
extern void setup_rainbow(); // forward declaration
|
|
extern void setup_rainbow(); // forward declaration
|
|
|
extern void setup_running(); // forward declaration
|
|
extern void setup_running(); // forward declaration
|
|
|
extern void setup_chasing();
|
|
extern void setup_chasing();
|
|
|
|
|
+extern void setup_random1();
|
|
|
|
|
|
|
|
-void (*setup_table[])() = {setup_rainbow, setup_running, setup_chasing};
|
|
|
|
|
|
|
+void (*setup_table[])() = {animation_off, setup_rainbow, setup_running, setup_chasing, setup_random1};
|
|
|
|
|
|
|
|
CRGB leds[NUM_LEDS];
|
|
CRGB leds[NUM_LEDS];
|
|
|
|
|
|
|
@@ -37,6 +42,7 @@ int status = WL_IDLE_STATUS;
|
|
|
WiFiServer server(80);
|
|
WiFiServer server(80);
|
|
|
|
|
|
|
|
void setup() {
|
|
void setup() {
|
|
|
|
|
+ setup_random1();
|
|
|
// put your setup code here, to run once:
|
|
// put your setup code here, to run once:
|
|
|
//Serial.begin(9600);
|
|
//Serial.begin(9600);
|
|
|
Serial.begin(9600);
|
|
Serial.begin(9600);
|
|
@@ -103,7 +109,7 @@ void loop() {
|
|
|
|
|
|
|
|
void process_HTTP() {
|
|
void process_HTTP() {
|
|
|
WiFiClient client = server.available();
|
|
WiFiClient client = server.available();
|
|
|
- if (client) {
|
|
|
|
|
|
|
+ if (client && millis() - latest_animation_change > 1000) {
|
|
|
int anim = 0;
|
|
int anim = 0;
|
|
|
Serial.println("new client");
|
|
Serial.println("new client");
|
|
|
// an http request ends with a blank line
|
|
// an http request ends with a blank line
|
|
@@ -128,10 +134,10 @@ void process_HTTP() {
|
|
|
}
|
|
}
|
|
|
anim %= NUMBER_OF_ANIMATIONS;
|
|
anim %= NUMBER_OF_ANIMATIONS;
|
|
|
client.println("HTTP/1.1 200 OK");
|
|
client.println("HTTP/1.1 200 OK");
|
|
|
- client.println("Content-Type: application/json");
|
|
|
|
|
|
|
+ client.println("Content-Type: text/plain");
|
|
|
client.println("Connection: close"); // the connection will be closed after completion of the response
|
|
client.println("Connection: close"); // the connection will be closed after completion of the response
|
|
|
client.println();
|
|
client.println();
|
|
|
- client.println("{}");
|
|
|
|
|
|
|
+ client.println("OK");
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
if (c == '/') {
|
|
if (c == '/') {
|
|
@@ -140,12 +146,14 @@ void process_HTTP() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
// give the web browser time to receive the data
|
|
// give the web browser time to receive the data
|
|
|
- delay(1);
|
|
|
|
|
|
|
+ delay(300);
|
|
|
|
|
|
|
|
// close the connection:
|
|
// close the connection:
|
|
|
client.stop();
|
|
client.stop();
|
|
|
//Serial.println("client disconnected");
|
|
//Serial.println("client disconnected");
|
|
|
setup_table[anim]();
|
|
setup_table[anim]();
|
|
|
|
|
+ current_animation = anim;
|
|
|
|
|
+ latest_animation_change = millis();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -168,7 +176,7 @@ void animation_running() {
|
|
|
leds[animation_i] = CRGB(100, 255, 200);
|
|
leds[animation_i] = CRGB(100, 255, 200);
|
|
|
FastLED.show();
|
|
FastLED.show();
|
|
|
animation_i++;
|
|
animation_i++;
|
|
|
- if (animation_i >= 49) {
|
|
|
|
|
|
|
+ if (animation_i >= 50) {
|
|
|
animation_i = 0;
|
|
animation_i = 0;
|
|
|
clear_strip();
|
|
clear_strip();
|
|
|
}
|
|
}
|
|
@@ -180,34 +188,185 @@ void animation_chasing() {
|
|
|
leds[animation_i] = CRGB(100, 255, 200);
|
|
leds[animation_i] = CRGB(100, 255, 200);
|
|
|
leds[(animation_i + 10) % 50] = CRGB(100, 255, 200);
|
|
leds[(animation_i + 10) % 50] = CRGB(100, 255, 200);
|
|
|
leds[(animation_i + 20) % 50] = CRGB(100, 255, 200);
|
|
leds[(animation_i + 20) % 50] = CRGB(100, 255, 200);
|
|
|
|
|
+ leds[(50 - animation_i) - 1] = 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();
|
|
|
animation_i++;
|
|
animation_i++;
|
|
|
animation_i %= 50;
|
|
animation_i %= 50;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void setup_rainbow() {
|
|
|
|
|
- Serial.println("Animation 1 setup");
|
|
|
|
|
|
|
+void animation_off() {
|
|
|
clear_strip();
|
|
clear_strip();
|
|
|
- animation_step_time = 100;
|
|
|
|
|
- animation_i = 0;
|
|
|
|
|
|
|
+ animation_step_time = 10000;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void animation_random1() {
|
|
|
|
|
+ for (int i = 0; i < NUM_LEDS/5; i++) {
|
|
|
|
|
+ int howManyCycles = animation_table_1[i][7];
|
|
|
|
|
+ int currentStep = animation_table_1[i][6];
|
|
|
|
|
+ uint8_t startRed = animation_table_1[i][0];
|
|
|
|
|
+ uint8_t startGreen = animation_table_1[i][1];
|
|
|
|
|
+ uint8_t startBlue = animation_table_1[i][2];
|
|
|
|
|
+ uint8_t goalRed = animation_table_1[i][3];
|
|
|
|
|
+ uint8_t goalGreen = animation_table_1[i][4];
|
|
|
|
|
+ uint8_t goalBlue = animation_table_1[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 < 5; led++) {
|
|
|
|
|
+ leds[led + i*5] = CRGB(r, b, g);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ animation_table_1[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);
|
|
|
|
|
+ animation_table_1[i][3] = newR;
|
|
|
|
|
+ animation_table_1[i][4] = newG;
|
|
|
|
|
+ animation_table_1[i][5] = newB;
|
|
|
|
|
+
|
|
|
|
|
+ uint8_t steps = (uint8_t) random(10, 50);
|
|
|
|
|
+ animation_table_1[i][0] = r;
|
|
|
|
|
+ animation_table_1[i][1] = g;
|
|
|
|
|
+ animation_table_1[i][2] = b;
|
|
|
|
|
+ animation_table_1[i][7] = steps;
|
|
|
|
|
+ animation_table_1[i][6] = 0;
|
|
|
|
|
+ if (i == 0) {
|
|
|
|
|
+ Serial.println(newR);
|
|
|
|
|
+ Serial.println(newG);
|
|
|
|
|
+ Serial.println(newB);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+// uint8_t r = leds[i*5].r + animation_table_1[i][0];
|
|
|
|
|
+// uint8_t g = leds[i*5].g + animation_table_1[i][1];
|
|
|
|
|
+// uint8_t b = leds[i*5].b + animation_table_1[i][2];
|
|
|
|
|
+// if (i == 0) {
|
|
|
|
|
+// Serial.println(r);
|
|
|
|
|
+// Serial.println(g);
|
|
|
|
|
+// Serial.println(b);
|
|
|
|
|
+// }
|
|
|
|
|
+// boolean rDone = false;
|
|
|
|
|
+// boolean gDone = false;
|
|
|
|
|
+// boolean bDone = false;
|
|
|
|
|
+// if (animation_table_1[i][0] > 0 && r >= animation_table_1[i][3]) {
|
|
|
|
|
+// r = animation_table_1[i][3];
|
|
|
|
|
+// rDone = true;
|
|
|
|
|
+// }
|
|
|
|
|
+// if (animation_table_1[i][1] > 0 && g >= animation_table_1[i][4]) {
|
|
|
|
|
+// g = animation_table_1[i][4];
|
|
|
|
|
+// gDone = true;
|
|
|
|
|
+// }
|
|
|
|
|
+// if (animation_table_1[i][2] > 0 && b >= animation_table_1[i][5]) {
|
|
|
|
|
+// b = animation_table_1[i][5];
|
|
|
|
|
+// bDone = true;
|
|
|
|
|
+// }
|
|
|
|
|
+// if (animation_table_1[i][0] <= 0 && r <= animation_table_1[i][3]) {
|
|
|
|
|
+// r = animation_table_1[i][3];
|
|
|
|
|
+// rDone = true;
|
|
|
|
|
+// }
|
|
|
|
|
+// if (animation_table_1[i][1] <= 0 && g <= animation_table_1[i][4]) {
|
|
|
|
|
+// g = animation_table_1[i][4];
|
|
|
|
|
+// gDone = true;
|
|
|
|
|
+// }
|
|
|
|
|
+// if (animation_table_1[i][2] <= 0 && b <= animation_table_1[i][5]) {
|
|
|
|
|
+// b = animation_table_1[i][5];
|
|
|
|
|
+// bDone = true;
|
|
|
|
|
+// }
|
|
|
|
|
+// if (i == 0) {
|
|
|
|
|
+// Serial.println(rDone);
|
|
|
|
|
+// Serial.println(gDone);
|
|
|
|
|
+// Serial.println(bDone);
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// for (int led = 0; led < 5; led++) {
|
|
|
|
|
+// leds[led + i*5] = CRGB(r, b, g);
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// if (rDone && gDone && bDone) {
|
|
|
|
|
+// if (i == 0) {
|
|
|
|
|
+// Serial.println("New color");
|
|
|
|
|
+// } else {
|
|
|
|
|
+// Serial.println("New color other i");
|
|
|
|
|
+// }
|
|
|
|
|
+// uint8_t newR = (uint8_t) random(0, 255);
|
|
|
|
|
+// uint8_t newG = (uint8_t) random(0, 255);
|
|
|
|
|
+// uint8_t newB = (uint8_t) random(0, 255);
|
|
|
|
|
+// animation_table_1[i][3] = newR;
|
|
|
|
|
+// animation_table_1[i][4] = newG;
|
|
|
|
|
+// animation_table_1[i][5] = newB;
|
|
|
|
|
+//
|
|
|
|
|
+// uint8_t steps = (uint8_t) random(10, 50);
|
|
|
|
|
+// uint8_t newRStep = (uint8_t) (newR - r)/steps;
|
|
|
|
|
+// uint8_t newGStep = (uint8_t) (newG - g)/steps;
|
|
|
|
|
+// uint8_t newBStep = (uint8_t) (newB - b)/steps;
|
|
|
|
|
+// if (newRStep < 1) {
|
|
|
|
|
+// newRStep = 1;
|
|
|
|
|
+// }
|
|
|
|
|
+// if (newGStep < 1) {
|
|
|
|
|
+// newGStep = 1;
|
|
|
|
|
+// }
|
|
|
|
|
+// if (newBStep < 1) {
|
|
|
|
|
+// newBStep = 1;
|
|
|
|
|
+// }
|
|
|
|
|
+// animation_table_1[i][0] = newRStep;
|
|
|
|
|
+// animation_table_1[i][1] = newGStep;
|
|
|
|
|
+// animation_table_1[i][2] = newBStep;
|
|
|
|
|
+// if (i == 0) {
|
|
|
|
|
+// Serial.println(newR);
|
|
|
|
|
+// Serial.println(newG);
|
|
|
|
|
+// Serial.println(newB);
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+ }
|
|
|
|
|
+ for (int i = 0; i < NUM_LEDS/5; i++) {
|
|
|
|
|
+ uint8_t startRed = leds[i*5].r;
|
|
|
|
|
+ uint8_t startGreen = leds[i*5].g;
|
|
|
|
|
+ uint8_t startBlue = leds[i*5].b;
|
|
|
|
|
+ uint8_t goalRed = leds[((i+1)*5)%NUM_LEDS].r;
|
|
|
|
|
+ uint8_t goalGreen = leds[((i+1)*5)%NUM_LEDS].g;
|
|
|
|
|
+ uint8_t goalBlue = leds[((i+1)*5)%NUM_LEDS].b;
|
|
|
|
|
+ for (int currentStep = 1; currentStep < 5; currentStep++) {
|
|
|
|
|
+ uint8_t r = (goalRed - startRed) * currentStep / 5 + startRed;
|
|
|
|
|
+ uint8_t g = (goalGreen - startGreen) * currentStep / 5 + startGreen;
|
|
|
|
|
+ uint8_t b = (goalBlue - startBlue) * currentStep / 5 + startBlue;
|
|
|
|
|
+ leds[i*5+currentStep] = CRGB(r, g, b);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ FastLED.show();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void setup_rainbow() {
|
|
|
|
|
+ normal_setup();
|
|
|
animation_var_1 = 10;
|
|
animation_var_1 = 10;
|
|
|
- current_animation = 0;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void setup_running() {
|
|
|
|
|
- Serial.println("Animation 2 setup");
|
|
|
|
|
|
|
+void normal_setup() {
|
|
|
clear_strip();
|
|
clear_strip();
|
|
|
animation_step_time = 100;
|
|
animation_step_time = 100;
|
|
|
animation_i = 0;
|
|
animation_i = 0;
|
|
|
animation_var_1 = 0;
|
|
animation_var_1 = 0;
|
|
|
- current_animation = 1;
|
|
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void setup_running() {
|
|
|
|
|
+ normal_setup();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void setup_chasing() {
|
|
void setup_chasing() {
|
|
|
- Serial.println("Animation 3 setup");
|
|
|
|
|
- clear_strip();
|
|
|
|
|
- animation_step_time = 100;
|
|
|
|
|
- animation_i = 0;
|
|
|
|
|
- animation_var_1 = 0;
|
|
|
|
|
- current_animation = 2;
|
|
|
|
|
|
|
+ normal_setup();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void setup_random1() {
|
|
|
|
|
+ for (int i = 0; i < NUM_LEDS; i++) {
|
|
|
|
|
+ for (int i = 0; i < 8; i++) {
|
|
|
|
|
+ animation_table_1[i][i] = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ //= {0, 0, 0, 0, 0, 0}; //Step size R, Step size G, Step size B, fR, fG, fB
|
|
|
|
|
+ //Start R, Start G, Start B, fR, fG, fB, cycle, how many cycles
|
|
|
|
|
+ }
|
|
|
|
|
+ normal_setup();
|
|
|
|
|
+ animation_step_time = 500;
|
|
|
}
|
|
}
|