// put your setup code here, to run once:
// byte r = 235;
// byte g = 200;
// byte b = 180;
#include <Arduino.h>
// #include <ESP
#include "config.h"
// #define LEN_STRIP {889,1046,892,823,1006,739,669,78}
// struct Mlinks; 2236962 1342177 147ae1
// struct MLinks {
// MyLED* l[3]; //Массив переходов
// uint8_t countLink; //Колличество переходов
// uint8_t stripNum;
// int ledNum;
// int stripLen;
// };
void setup() {
Serial.begin(115200);
Serial.setTimeout(1);
randomSeed(analogRead(4));
start = micros();
// struct Points {
// uint8_t strip;
// int num;
// LedRole role;
// uint8_t count;
// uint8_t marr[3]; setLink
// };
Points points[POINTS] = {{0, 0, START, 1, {24, 0, 0}}, {0, 143, RANDOM, 1, {46, 0, 0}}, {0, 318, END, 3, {3, 31, 40}}, {0, 319, START, 3, {2, 31, 40}}, {0, 354, RANDOM, 1, {30, 0, 0}}, {0, 673, END, 1, {17, 0, 0}}, {0, 674, START, 1, {16, 0, 0}}, {0, 884, END, 1, {14, 0, 0}}, {1, 0, START, 0, {0, 0, 0}}, {1, 461, END, 2, {10, 26, 0}}, {1, 462, START, 2, {9, 26, 0}}, {1, 696, END, 1, {20, 0, 0}}, {1, 697, START, 1, {19, 0, 0}}, {1, 772, END, 0, {0, 0, 0}}, {1, 773, START, 1, {7, 0, 0}}, {1, 1046, END, 0, {0, 0, 0}}, {2, 0, START, 1, {6, 0, 0}}, {2, 19, RANDOM, 1, {5, 0, 0}}, {2, 198, RANDOM, 1, {43, 0, 0}}, {2, 320, RANDOM, 1, {12, 0, 0}}, {2, 420, RANDOM, 1, {11, 0, 0}}, {2, 892, END, 0, {0, 0, 0}}, {3, 0, START, 0, {0, 0, 0}}, {3, 511, RANDOM, 1, {41, 0, 0}}, {3, 596, RANDOM, 1, {0, 0, 0}}, {3, 823, END, 1, {33, 0, 0}}, {4, 0, START, 2, {9, 10, 0}}, {4, 128, RANDOM, 1, {42, 0, 0}}, {4, 308, END, 1, {44, 0, 0}}, {4, 309, START, 1, {45, 0, 0}}, {4, 480, END, 1, {4, 0, 0}}, {4, 481, START, 3, {2, 3, 40}}, {4, 634, RANDOM, 1, {39, 0, 0}}, {4, 801, RANDOM, 1, {25, 0, 0}}, {4, 903, RANDOM, 1, {36, 0, 0}}, {4, 1006, END, 0, {0, 0, 0}}, {5, 0, START, 1, {34, 0, 0}}, {5, 172, END, 0, {0, 0, 0}}, {5, 178, START, 0, {0, 0, 0}}, {5, 365, RANDOM, 1, {32, 0, 0}}, {5, 739, END, 3, {2, 3, 31}}, {6, 0, START, 1, {23, 0, 0}}, {6, 285, END, 1, {27, 0, 0}}, {6, 286, START, 1, {18, 0, 0}}, {6, 461, RANDOM, 1, {28, 0, 0}}, {6, 556, RANDOM, 1, {29, 0, 0}}, {6, 669, END, 1, {1, 0, 0}}, {7, 0, START, 0, {0, 0, 0}}, {7, 78, END, 0, {0, 0, 0}}};
// Points points[POINTS] = {{0, 0},{0, 159}, {0, 318}, {0, 319}, {0, 354}, {0, 673}, {0, 674}, {0, 884},{1,0},{1, 461}, {1, 462}, {1, 696}, {1, 697},{1,772},{1,773},{1,1046}, {2, 0},{2,23}, {2, 198}, {2, 320}, {2, 420},{2,892},{3,0}, {3, 511}, {3, 596}, {3, 823}, {4, 0}, {4, 128}, {4, 308}, {4, 309}, {4, 480}, {4, 481}, {4, 634}, {4, 801}, {4, 903},{4,1006},{5,0}, {5, 172}, {5, 178}, {5, 365}, {5, 739}, {6, 0}, {6, 285}, {6, 286}, {6, 461}, {6, 556},{6,669},{7,0},{7,78}};
for (int i = 0 ; i < POINTS; i++) {
// StripPoint[i].strip = points[i].strip;
// StripPoint[i].ledNum = points[i].num;
setLedNum(&StripPoint[i].ledNum, points[i].num, points[i].strip);
StripPoint[i].setRole(points[i].role);
myColor[StripPoint[i].getNum()].linked();
myColor[StripPoint[i].getNum()].setLink(byte(i));
// Serial.print(String(" Point # ")+i+ " : "+ StripPoint[i].getNum() + " role: " + StripPoint[i].getRole() + " ");
// Serial.print(String(" count : ") + points[i].count);
StripPoint[i].count = points[i].count;
for (int j = 0 ; j < points[i].count; j++) {
setLedNum(&StripPoint[i].arr[j], points[points[i].marr[j]].num, points[points[i].marr[j]].strip );
StripPoint[i].setRole(points[points[i].marr[j]].role, j);
// Serial.print(String(" ")+ StripPoint[i].getNum(j) + " role: "+ StripPoint[i].getRole(j)+ " ");
// Serial.println(random(2));
}
// Serial.println(uniformRandom(0,300));
// Serial.println();
// StripPoint[i].strip = point[i].strip
// funcState.name = SNAKE;
myColor[0].setRGB(uint8_t(0xff));
funcState.state = FEND;
}
for (int i = 0 ; i < ALL_STRIPS_LEN; i++) {
// Serial.println(String("led: ")+i+ " state: "+ myColor[i].isLinked());
}
stop = int(micros() - start);
Serial.println(String("Time on Config : ") + stop + "mc/s");
}
// struct FuncControl{
// FuncState state; //FuncState {STOP,FSTART,RUN,FEND};
// FuncList name; //FuncList {NONE,STAR,SNAKE,RAINBOW};
// // boolean srarted;
// };
// enum LedRole {RANDOM, UP, DOWN, START, END, NUN};
// long nowTime = micros();
uint8_t bright = 255;
boolean tikControl;
// long start;
void loop() {
if (Serial.available() > 0) {
initSerial = Serial.parseInt();
if (funcState.state == RUN) {
Serial.println("Set stop");
delay(1000);
funcState.state = STOP;
} else {
funcState.name = FuncList(initSerial);
if (funcState.name == STAR) {
tikControl = true;
}
funcState.state = FSTART;
}
// funcState.name = FuncList(initSerial);
Serial.parseInt();
Serial.println(String("name : ") + funcState.name + " role: " + funcState.state);
}
if (tikControl) {
start = millis();
tikControl = false;
}
switch (funcState.name) {
case STAR:
if (funcState.state == FSTART) {
starEffect();
} else if (millis() > start + 300) {
starEffect();
tikControl = true;
}
break;
case SNAKE:
snakeEffect();
stop = millis() - start;
Serial.println(String("Snake time : ") + stop + " mcs" );
break;
case PULSE:
pulseEffect();
stop = millis() - start;
Serial.println(String("Pulse time : ") + stop + " mcs" );
start = millis();
break;
}
}