|
@@ -2,13 +2,13 @@
|
|
|
#include <SPI.h>
|
|
#include <SPI.h>
|
|
|
#include <WiFiNINA.h>
|
|
#include <WiFiNINA.h>
|
|
|
|
|
|
|
|
-#define NUM_LEDS 150
|
|
|
|
|
|
|
+#define NUM_LEDS 150
|
|
|
//50
|
|
//50
|
|
|
#define DATA_PIN 9
|
|
#define DATA_PIN 9
|
|
|
-int NUMBER_OF_ANIMATIONS = 6;
|
|
|
|
|
|
|
+int NUMBER_OF_ANIMATIONS = 7;
|
|
|
int NUMBER_OF_LEDS = 150;
|
|
int NUMBER_OF_LEDS = 150;
|
|
|
-char ssid[] = "Pannkakshuset";
|
|
|
|
|
-char pass[] = "lavalampa";
|
|
|
|
|
|
|
+char ssid[] = "Telia-E39815";
|
|
|
|
|
+char pass[] = "B3C606D8E7";
|
|
|
boolean doing_animation = true;
|
|
boolean doing_animation = true;
|
|
|
|
|
|
|
|
int current_animation = 0;
|
|
int current_animation = 0;
|
|
@@ -17,7 +17,7 @@ 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;
|
|
|
-uint16_t animation_table_1[10][8] = {};
|
|
|
|
|
|
|
+int animation_table_1[10][8] = {};
|
|
|
|
|
|
|
|
long last_animation_millis = millis();
|
|
long last_animation_millis = millis();
|
|
|
long latest_animation_change = millis();
|
|
long latest_animation_change = millis();
|
|
@@ -29,15 +29,17 @@ extern void animation_chasing();
|
|
|
extern void animation_off();
|
|
extern void animation_off();
|
|
|
extern void animation_random1();
|
|
extern void animation_random1();
|
|
|
extern void animation_rgb_light();
|
|
extern void animation_rgb_light();
|
|
|
|
|
+extern void animation_random2();
|
|
|
|
|
|
|
|
-void (*animation_table[])() = {animation_off, animation_rainbow, animation_running, animation_chasing, animation_random1, animation_rgb_light};
|
|
|
|
|
|
|
+void (*animation_table[])() = {animation_off, animation_rainbow, animation_running, animation_chasing, animation_random1, animation_rgb_light, animation_random2};
|
|
|
|
|
|
|
|
extern void setup_rainbow(); // forward declaration
|
|
extern void setup_rainbow(); // forward declaration
|
|
|
extern void setup_random1();
|
|
extern void setup_random1();
|
|
|
extern void normal_setup();
|
|
extern void normal_setup();
|
|
|
extern void setup_chosen(int, int, CRGB, boolean, int, int);
|
|
extern void setup_chosen(int, int, CRGB, boolean, int, int);
|
|
|
|
|
+extern void setup_random2();
|
|
|
|
|
|
|
|
-void (*setup_table[])() = {animation_off, setup_rainbow, normal_setup, normal_setup, setup_random1, normal_setup};
|
|
|
|
|
|
|
+void (*setup_table[])() = {animation_off, setup_rainbow, normal_setup, normal_setup, setup_random1, normal_setup, setup_random2};
|
|
|
|
|
|
|
|
CRGB leds[NUM_LEDS];
|
|
CRGB leds[NUM_LEDS];
|
|
|
|
|
|
|
@@ -53,23 +55,27 @@ void setup() {
|
|
|
while (!Serial) {
|
|
while (!Serial) {
|
|
|
; // wait for serial port to connect. Needed for native USB port only
|
|
; // wait for serial port to connect. Needed for native USB port only
|
|
|
}
|
|
}
|
|
|
|
|
+ Serial.println("Starting");
|
|
|
|
|
|
|
|
FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); //TM1804 BRG
|
|
FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); //TM1804 BRG
|
|
|
FastLED.setBrightness(255);
|
|
FastLED.setBrightness(255);
|
|
|
FastLED.clear();
|
|
FastLED.clear();
|
|
|
FastLED.show();
|
|
FastLED.show();
|
|
|
|
|
+
|
|
|
|
|
+ Serial.println("Connected LEDs");
|
|
|
delay(1000);
|
|
delay(1000);
|
|
|
|
|
|
|
|
- for (int i = 15; i >= 10; i--) { //Remove this when small spce left
|
|
|
|
|
- uint8_t color = i*(NUM_LEDS/10 - 1) + NUM_LEDS/10;
|
|
|
|
|
- for (int currentLed = 5; currentLed >= 0; currentLed--) {
|
|
|
|
|
- leds[currentLed + i*5] = CRGB(color, 255-color, 0);
|
|
|
|
|
- leds[5-currentLed + NUM_LEDS/2-5 + ((NUM_LEDS/10 - i)*5)] = CRGB(color, 255-color, 0);
|
|
|
|
|
- FastLED.show();
|
|
|
|
|
- delay(5*i/3 + random(0, 25*i + 1) + 1);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ // for (int i = 15; i >= 10; i--) { //Remove this when small spce left
|
|
|
|
|
+ // uint8_t color = i*(NUM_LEDS/10 - 1) + NUM_LEDS/10;
|
|
|
|
|
+ // for (int currentLed = 5; currentLed >= 0; currentLed--) {
|
|
|
|
|
+ // leds[currentLed + i*5] = CRGB(color, 255-color, 0);
|
|
|
|
|
+ // leds[5-currentLed + NUM_LEDS/2-5 + ((NUM_LEDS/10 - i)*5)] = CRGB(color, 255-color, 0);
|
|
|
|
|
+ // FastLED.show();
|
|
|
|
|
+ // delay(5*i/3 + random(0, 25*i + 1) + 1);
|
|
|
|
|
+ // }
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
//pinMode(DATA_PIN, OUTPUT);
|
|
//pinMode(DATA_PIN, OUTPUT);
|
|
|
boolean first_check = true;
|
|
boolean first_check = true;
|
|
|
while (status != WL_CONNECTED) {
|
|
while (status != WL_CONNECTED) {
|
|
@@ -86,31 +92,33 @@ void setup() {
|
|
|
delay(10000);
|
|
delay(10000);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ Serial.println("Connected to WiFi");
|
|
|
|
|
|
|
|
- for (int i = 10; i >= 5; i--) { //Remove this when small spce left
|
|
|
|
|
- uint8_t color = i*(NUM_LEDS/10 - 1) + NUM_LEDS/10;
|
|
|
|
|
- for (int currentLed = 5; currentLed >= 0; currentLed--) {
|
|
|
|
|
- leds[currentLed + i*5] = CRGB(color, 255-color, 0);
|
|
|
|
|
- leds[5-currentLed + NUM_LEDS/2-5 + ((NUM_LEDS/10 - i)*5)] = CRGB(color, 255-color, 0);
|
|
|
|
|
- FastLED.show();
|
|
|
|
|
- delay(5*i/3 + random(0, 25*i + 1) + 1);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ // for (int i = 10; i >= 5; i--) { //Remove this when small spce left
|
|
|
|
|
+ // uint8_t color = i*(NUM_LEDS/10 - 1) + NUM_LEDS/10;
|
|
|
|
|
+ // for (int currentLed = 5; currentLed >= 0; currentLed--) {
|
|
|
|
|
+ // leds[currentLed + i*5] = CRGB(color, 255-color, 0);
|
|
|
|
|
+ // leds[5-currentLed + NUM_LEDS/2-5 + ((NUM_LEDS/10 - i)*5)] = CRGB(color, 255-color, 0);
|
|
|
|
|
+ // FastLED.show();
|
|
|
|
|
+ // delay(5*i/3 + random(0, 25*i + 1) + 1);
|
|
|
|
|
+ // }
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ Serial.println(WiFi.localIP());
|
|
|
server.begin();
|
|
server.begin();
|
|
|
|
|
|
|
|
delay(1000);
|
|
delay(1000);
|
|
|
Serial.println("Ready");
|
|
Serial.println("Ready");
|
|
|
|
|
|
|
|
- for (int i = 5; i >= 0; i--) { //insert this when small space -> for (int i = (NUM_LEDS / 5) / 2; i >= 0; i--) {
|
|
|
|
|
- uint8_t color = i*(NUM_LEDS/10 - 1) + NUM_LEDS/10;
|
|
|
|
|
- for (int currentLed = 5; currentLed >= 0; currentLed--) {
|
|
|
|
|
- leds[currentLed + i*5] = CRGB(color, 255-color, 0);
|
|
|
|
|
- leds[5-currentLed + NUM_LEDS/2-5 + ((NUM_LEDS/10 - i)*5)] = CRGB(color, 255-color, 0);
|
|
|
|
|
- FastLED.show();
|
|
|
|
|
- delay(5*i/3 + random(0, 25*i + 1) + 1);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // for (int i = 5; i >= 0; i--) { //insert this when small space -> for (int i = (NUM_LEDS / 5) / 2; i >= 0; i--) {
|
|
|
|
|
+ // uint8_t color = i*(NUM_LEDS/10 - 1) + NUM_LEDS/10;
|
|
|
|
|
+ // for (int currentLed = 5; currentLed >= 0; currentLed--) {
|
|
|
|
|
+ // leds[currentLed + i*5] = CRGB(color, 255-color, 0);
|
|
|
|
|
+ // leds[5-currentLed + NUM_LEDS/2-5 + ((NUM_LEDS/10 - i)*5)] = CRGB(color, 255-color, 0);
|
|
|
|
|
+ // FastLED.show();
|
|
|
|
|
+ // delay(5*i/3 + random(0, 25*i + 1) + 1);
|
|
|
|
|
+ // }
|
|
|
|
|
+ // }
|
|
|
delay(1000);
|
|
delay(1000);
|
|
|
current_animation = 0;
|
|
current_animation = 0;
|
|
|
setup_table[current_animation]();
|
|
setup_table[current_animation]();
|
|
@@ -134,6 +142,13 @@ void loop() {
|
|
|
} else {
|
|
} else {
|
|
|
loops_since_http = 0;
|
|
loops_since_http = 0;
|
|
|
//Serial.println("Waiting for animation");
|
|
//Serial.println("Waiting for animation");
|
|
|
|
|
+ status=WiFi.status();
|
|
|
|
|
+ if (status == WL_DISCONNECTED || status == WL_CONNECTION_LOST) {
|
|
|
|
|
+ while (status != WL_CONNECTED) {
|
|
|
|
|
+ status = WiFi.begin(ssid, pass);
|
|
|
|
|
+ delay(1000);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
process_HTTP();
|
|
process_HTTP();
|
|
|
delay(1);
|
|
delay(1);
|
|
|
}
|
|
}
|
|
@@ -162,8 +177,7 @@ void process_HTTP() {
|
|
|
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
|
|
|
- boolean foundSlash = false;
|
|
|
|
|
- boolean foundHashtag = false;
|
|
|
|
|
|
|
+ int readingState = 0;
|
|
|
int leds1 = 0;
|
|
int leds1 = 0;
|
|
|
int leds2 = 0;
|
|
int leds2 = 0;
|
|
|
uint8_t newR = 0;
|
|
uint8_t newR = 0;
|
|
@@ -173,12 +187,14 @@ void process_HTTP() {
|
|
|
int cycles = 20;
|
|
int cycles = 20;
|
|
|
int cycleLength = 100;
|
|
int cycleLength = 100;
|
|
|
int currentLoop = 0;
|
|
int currentLoop = 0;
|
|
|
|
|
+ int setting = 0;
|
|
|
|
|
+ int value = 0;
|
|
|
String fullArguments = "";
|
|
String fullArguments = "";
|
|
|
while (client.connected()) {
|
|
while (client.connected()) {
|
|
|
if (client.available()) {
|
|
if (client.available()) {
|
|
|
char c = client.read();
|
|
char c = client.read();
|
|
|
//Serial.write(c);
|
|
//Serial.write(c);
|
|
|
- if (foundHashtag) { //http://192.168.112.41/z0:49:0:255:0:0:20:1000;
|
|
|
|
|
|
|
+ if (readingState == 2) { //http://192.168.112.41/z0:49:0:255:0:0:20:1000;
|
|
|
if (c == ';') {
|
|
if (c == ';') {
|
|
|
client.println("HTTP/1.1 200 OK");
|
|
client.println("HTTP/1.1 200 OK");
|
|
|
client.println("Content-Type: text/plain");
|
|
client.println("Content-Type: text/plain");
|
|
@@ -209,10 +225,35 @@ void process_HTTP() {
|
|
|
} else {
|
|
} else {
|
|
|
fullArguments = fullArguments + c;
|
|
fullArguments = fullArguments + c;
|
|
|
}
|
|
}
|
|
|
- } else if (foundSlash) {
|
|
|
|
|
- if (c == 'z') {
|
|
|
|
|
- foundHashtag = true;
|
|
|
|
|
- foundSlash = false;
|
|
|
|
|
|
|
+ } else if (readingState == 3) {
|
|
|
|
|
+ Serial.println("Inside readingState == 3");
|
|
|
|
|
+ if (c == ';') {
|
|
|
|
|
+ client.println("HTTP/1.1 200 OK");
|
|
|
|
|
+ client.println("Content-Type: text/plain");
|
|
|
|
|
+ client.println("Connection: close"); // the connection will be closed after completion of the response
|
|
|
|
|
+ client.println();
|
|
|
|
|
+ client.println("OK");
|
|
|
|
|
+ break;
|
|
|
|
|
+ } else if (c == ':') {
|
|
|
|
|
+ if (currentLoop == 0) {
|
|
|
|
|
+ setting = fullArguments.toInt();
|
|
|
|
|
+ } else if (currentLoop == 1) {
|
|
|
|
|
+ value = fullArguments.toInt();
|
|
|
|
|
+ Serial.println(value);
|
|
|
|
|
+ }
|
|
|
|
|
+ fullArguments = "";
|
|
|
|
|
+ currentLoop++;
|
|
|
|
|
+ Serial.println(currentLoop);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ fullArguments = fullArguments + c;
|
|
|
|
|
+ Serial.println(fullArguments);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (readingState != 0) {
|
|
|
|
|
+ if (c == 'y') {
|
|
|
|
|
+ readingState = 3;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ } if (c == 'z') {
|
|
|
|
|
+ readingState = 2;
|
|
|
continue;
|
|
continue;
|
|
|
} else if (c == '(') {
|
|
} else if (c == '(') {
|
|
|
anim = current_animation - 1;
|
|
anim = current_animation - 1;
|
|
@@ -237,7 +278,7 @@ void process_HTTP() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (c == '/') {
|
|
if (c == '/') {
|
|
|
- foundSlash = true;
|
|
|
|
|
|
|
+ readingState = 1;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -247,19 +288,28 @@ void process_HTTP() {
|
|
|
// close the connection:
|
|
// close the connection:
|
|
|
client.stop();
|
|
client.stop();
|
|
|
//Serial.println("client disconnected");
|
|
//Serial.println("client disconnected");
|
|
|
- if (foundSlash) {
|
|
|
|
|
|
|
+ if (readingState == 1) {
|
|
|
doing_animation = true;
|
|
doing_animation = true;
|
|
|
setup_table[anim]();
|
|
setup_table[anim]();
|
|
|
current_animation = anim;
|
|
current_animation = anim;
|
|
|
latest_animation_change = millis();
|
|
latest_animation_change = millis();
|
|
|
- } else {
|
|
|
|
|
|
|
+
|
|
|
|
|
+ } else if (readingState == 3) {
|
|
|
|
|
+ Serial.println(setting);
|
|
|
|
|
+ Serial.println(value);
|
|
|
|
|
+ if (setting == 1) {
|
|
|
|
|
+ animation_step_time = value;
|
|
|
|
|
+ } else if (setting == 2) {
|
|
|
|
|
+ animation_var_1 = value;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (readingState == 2) {
|
|
|
doing_animation = false;
|
|
doing_animation = false;
|
|
|
-// Serial.println(leds1);
|
|
|
|
|
-// Serial.println(leds2);
|
|
|
|
|
-// Serial.println(newR);
|
|
|
|
|
-// Serial.println(newG);
|
|
|
|
|
-// Serial.println(newB);
|
|
|
|
|
-// Serial.println(doFade);
|
|
|
|
|
|
|
+ // Serial.println(leds1);
|
|
|
|
|
+ // Serial.println(leds2);
|
|
|
|
|
+ // Serial.println(newR);
|
|
|
|
|
+ // Serial.println(newG);
|
|
|
|
|
+ // Serial.println(newB);
|
|
|
|
|
+ // Serial.println(doFade);
|
|
|
setup_chosen(leds1, leds2, CRGB(newR, newG, newB), (boolean) doFade, cycles, cycleLength);
|
|
setup_chosen(leds1, leds2, CRGB(newR, newG, newB), (boolean) doFade, cycles, cycleLength);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|