WiFi подключение переработано, код переформатирован, добавлены комментарии

This commit is contained in:
gunner47
2019-07-16 22:50:56 +03:00
parent 90a13acc74
commit 0965f3d46a
10 changed files with 625 additions and 317 deletions

View File

@@ -1,8 +1,10 @@
// ================================= ЭФФЕКТЫ ====================================
// ============= ЭФФЕКТЫ ===============
// --------------------------------- конфетти ------------------------------------
void sparklesRoutine() {
for (byte i = 0; i < modes[0].scale; i++) {
// ------------- конфетти --------------
void sparklesRoutine()
{
for (byte i = 0; i < modes[0].scale; i++)
{
byte x = random(0, WIDTH);
byte y = random(0, HEIGHT);
if (getPixColorXY(x, y) == 0)
@@ -12,34 +14,42 @@ void sparklesRoutine() {
}
// функция плавного угасания цвета для всех пикселей
void fader(byte step) {
for (byte i = 0; i < WIDTH; i++) {
for (byte j = 0; j < HEIGHT; j++) {
void fader(byte step)
{
for (byte i = 0; i < WIDTH; i++)
{
for (byte j = 0; j < HEIGHT; j++)
{
fadePixel(i, j, step);
}
}
}
void fadePixel(byte i, byte j, byte step) { // новый фейдер
int pixelNum = getPixelNumber(i, j);
void fadePixel(byte i, byte j, byte step) // новый фейдер
{
int32_t pixelNum = getPixelNumber(i, j);
if (getPixColor(pixelNum) == 0) return;
if (leds[pixelNum].r >= 30 ||
leds[pixelNum].g >= 30 ||
leds[pixelNum].b >= 30) {
leds[pixelNum].b >= 30)
{
leds[pixelNum].fadeToBlackBy(step);
} else {
}
else
{
leds[pixelNum] = 0;
}
}
// -------------------------------------- огонь ---------------------------------------------
// эффект "огонь"
#define SPARKLES 1 // вылетающие угольки вкл выкл
// ------------- огонь -----------------
#define SPARKLES 1 // вылетающие угольки вкл выкл
unsigned char line[WIDTH];
int pcnt = 0;
int32_t pcnt = 0;
//these values are substracetd from the generated values to give a shape to the animation
const unsigned char valueMask[8][16] PROGMEM = {
const unsigned char valueMask[8][16] PROGMEM =
{
{32 , 0 , 0 , 0 , 0 , 0 , 0 , 32 , 32 , 0 , 0 , 0 , 0 , 0 , 0 , 32 },
{64 , 0 , 0 , 0 , 0 , 0 , 0 , 64 , 64 , 0 , 0 , 0 , 0 , 0 , 0 , 64 },
{96 , 32 , 0 , 0 , 0 , 0 , 32 , 96 , 96 , 32 , 0 , 0 , 0 , 0 , 32 , 96 },
@@ -52,7 +62,8 @@ const unsigned char valueMask[8][16] PROGMEM = {
//these are the hues for the fire,
//should be between 0 (red) to about 25 (yellow)
const unsigned char hueMask[8][16] PROGMEM = {
const unsigned char hueMask[8][16] PROGMEM =
{
{1 , 11, 19, 25, 25, 22, 11, 1 , 1 , 11, 19, 25, 25, 22, 11, 1 },
{1 , 8 , 13, 19, 25, 19, 8 , 1 , 1 , 8 , 13, 19, 25, 19, 8 , 1 },
{1 , 8 , 13, 16, 19, 16, 8 , 1 , 1 , 8 , 13, 16, 19, 16, 8 , 1 },
@@ -63,13 +74,16 @@ const unsigned char hueMask[8][16] PROGMEM = {
{0 , 0 , 0 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 1 , 0 , 0 , 0 }
};
void fireRoutine() {
if (loadingFlag) {
void fireRoutine()
{
if (loadingFlag)
{
loadingFlag = false;
//FastLED.clear();
generateLine();
}
if (pcnt >= 100) {
if (pcnt >= 100)
{
shiftUp();
generateLine();
pcnt = 0;
@@ -79,16 +93,20 @@ void fireRoutine() {
}
// Randomly generate the next line (matrix row)
void generateLine() {
for (uint8_t x = 0; x < WIDTH; x++) {
void generateLine()
{
for (uint8_t x = 0; x < WIDTH; x++)
{
line[x] = random(64, 255);
}
}
void shiftUp() {
for (uint8_t y = HEIGHT - 1; y > 0; y--) {
for (uint8_t x = 0; x < WIDTH; x++) {
void shiftUp()
{
for (uint8_t y = HEIGHT - 1; y > 0; y--)
{
for (uint8_t x = 0; x < WIDTH; x++)
{
uint8_t newX = x;
if (x > 15) newX = x - 15;
if (y > 7) continue;
@@ -96,7 +114,8 @@ void shiftUp() {
}
}
for (uint8_t x = 0; x < WIDTH; x++) {
for (uint8_t x = 0; x < WIDTH; x++)
{
uint8_t newX = x;
if (x > 15) newX = x - 15;
matrixValue[0][newX] = line[newX];
@@ -106,98 +125,118 @@ void shiftUp() {
// draw a frame, interpolating between 2 "key frames"
// @param pcnt percentage of interpolation
void drawFrame(int pcnt) {
int nextv;
void drawFrame(int32_t pcnt)
{
int32_t nextv;
//each row interpolates with the one before it
for (unsigned char y = HEIGHT - 1; y > 0; y--) {
for (unsigned char x = 0; x < WIDTH; x++) {
for (unsigned char y = HEIGHT - 1; y > 0; y--)
{
for (unsigned char x = 0; x < WIDTH; x++)
{
uint8_t newX = x;
if (x > 15) newX = x - 15;
if (y < 8) {
if (y < 8)
{
nextv =
(((100.0 - pcnt) * matrixValue[y][newX]
+ pcnt * matrixValue[y - 1][newX]) / 100.0)
- pgm_read_byte(&(valueMask[y][newX]));
CRGB color = CHSV(
modes[1].scale * 2.5 + pgm_read_byte(&(hueMask[y][newX])), // H
255, // S
(uint8_t)max(0, nextv) // V
);
modes[1].scale * 2.5 + pgm_read_byte(&(hueMask[y][newX])), // H
255, // S
(uint8_t)max(0, nextv) // V
);
leds[getPixelNumber(x, y)] = color;
} else if (y == 8 && SPARKLES) {
}
else if (y == 8 && SPARKLES)
{
if (random(0, 20) == 0 && getPixColorXY(x, y - 1) != 0) drawPixelXY(x, y, getPixColorXY(x, y - 1));
else drawPixelXY(x, y, 0);
} else if (SPARKLES) {
}
else if (SPARKLES)
{
// старая версия для яркости
if (getPixColorXY(x, y - 1) > 0)
drawPixelXY(x, y, getPixColorXY(x, y - 1));
else drawPixelXY(x, y, 0);
}
}
}
//first row interpolates with the "next" line
for (unsigned char x = 0; x < WIDTH; x++) {
for (unsigned char x = 0; x < WIDTH; x++)
{
uint8_t newX = x;
if (x > 15) newX = x - 15;
CRGB color = CHSV(
modes[1].scale * 2.5 + pgm_read_byte(&(hueMask[0][newX])), // H
255, // S
(uint8_t)(((100.0 - pcnt) * matrixValue[0][newX] + pcnt * line[newX]) / 100.0) // V
);
modes[1].scale * 2.5 + pgm_read_byte(&(hueMask[0][newX])), // H
255, // S
(uint8_t)(((100.0 - pcnt) * matrixValue[0][newX] + pcnt * line[newX]) / 100.0) // V
);
leds[getPixelNumber(newX, 0)] = color;
}
}
byte hue;
// ---------------------------------------- радуга ------------------------------------------
void rainbowVertical() {
// ------------- радуга ----------------
void rainbowVertical()
{
hue += 2;
for (byte j = 0; j < HEIGHT; j++) {
for (byte j = 0; j < HEIGHT; j++)
{
CHSV thisColor = CHSV((byte)(hue + j * modes[2].scale), 255, 255);
for (byte i = 0; i < WIDTH; i++)
drawPixelXY(i, j, thisColor);
}
}
void rainbowHorizontal() {
void rainbowHorizontal()
{
hue += 2;
for (byte i = 0; i < WIDTH; i++) {
for (byte i = 0; i < WIDTH; i++)
{
CHSV thisColor = CHSV((byte)(hue + i * modes[3].scale), 255, 255);
for (byte j = 0; j < HEIGHT; j++)
drawPixelXY(i, j, thisColor); //leds[getPixelNumber(i, j)] = thisColor;
drawPixelXY(i, j, thisColor); //leds[getPixelNumber(i, j)] = thisColor;
}
}
// ---------------------------------------- ЦВЕТА ------------------------------------------
void colorsRoutine() {
// ------------- цвета -----------------
void colorsRoutine()
{
hue += modes[4].scale;
for (int i = 0; i < NUM_LEDS; i++) {
for (int32_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = CHSV(hue, 255, 255);
}
}
// --------------------------------- ЦВЕТ ------------------------------------
void colorRoutine() {
for (int i = 0; i < NUM_LEDS; i++) {
// ------------- цвет ------------------
void colorRoutine()
{
for (int32_t i = 0; i < NUM_LEDS; i++)
{
leds[i] = CHSV(modes[14].scale * 2.5, 255, 255);
}
}
// ------------------------------ снегопад 2.0 --------------------------------
void snowRoutine() {
// ------------- снегопад 2.0 ----------
void snowRoutine()
{
// сдвигаем всё вниз
for (byte x = 0; x < WIDTH; x++) {
for (byte y = 0; y < HEIGHT - 1; y++) {
for (byte x = 0; x < WIDTH; x++)
{
for (byte y = 0; y < HEIGHT - 1; y++)
{
drawPixelXY(x, y, getPixColorXY(x, y + 1));
}
}
for (byte x = 0; x < WIDTH; x++) {
for (byte x = 0; x < WIDTH; x++)
{
// заполняем случайно верхнюю строку
// а также не даём двум блокам по вертикали вместе быть
if (getPixColorXY(x, HEIGHT - 2) == 0 && (random(0, modes[15].scale) == 0))
@@ -207,9 +246,11 @@ void snowRoutine() {
}
}
// ------------------------------ МАТРИЦА ------------------------------
void matrixRoutine() {
for (byte x = 0; x < WIDTH; x++) {
// ------------- матрица ---------------
void matrixRoutine()
{
for (byte x = 0; x < WIDTH; x++)
{
// заполняем случайно верхнюю строку
uint32_t thisColor = getPixColorXY(x, HEIGHT - 1);
if (thisColor == 0)
@@ -221,29 +262,34 @@ void matrixRoutine() {
}
// сдвигаем всё вниз
for (byte x = 0; x < WIDTH; x++) {
for (byte y = 0; y < HEIGHT - 1; y++) {
for (byte x = 0; x < WIDTH; x++)
{
for (byte y = 0; y < HEIGHT - 1; y++)
{
drawPixelXY(x, y, getPixColorXY(x, y + 1));
}
}
}
// ----------------------------- СВЕТЛЯКИ ------------------------------
// ------------- светляки --------------
#define LIGHTERS_AM 100
int lightersPos[2][LIGHTERS_AM];
int32_t lightersPos[2][LIGHTERS_AM];
int8_t lightersSpeed[2][LIGHTERS_AM];
CHSV lightersColor[LIGHTERS_AM];
byte loopCounter;
int angle[LIGHTERS_AM];
int speedV[LIGHTERS_AM];
int32_t angle[LIGHTERS_AM];
int32_t speedV[LIGHTERS_AM];
int8_t angleSpeed[LIGHTERS_AM];
void lightersRoutine() {
if (loadingFlag) {
void lightersRoutine()
{
if (loadingFlag)
{
loadingFlag = false;
randomSeed(millis());
for (byte i = 0; i < LIGHTERS_AM; i++) {
for (byte i = 0; i < LIGHTERS_AM; i++)
{
lightersPos[0][i] = random(0, WIDTH * 10);
lightersPos[1][i] = random(0, HEIGHT * 10);
lightersSpeed[0][i] = random(-10, 10);
@@ -253,8 +299,10 @@ void lightersRoutine() {
}
FastLED.clear();
if (++loopCounter > 20) loopCounter = 0;
for (byte i = 0; i < modes[17].scale; i++) {
if (loopCounter == 0) { // меняем скорость каждые 255 отрисовок
for (byte i = 0; i < modes[17].scale; i++)
{
if (loopCounter == 0) // меняем скорость каждые 255 отрисовок
{
lightersSpeed[0][i] += random(-3, 4);
lightersSpeed[1][i] += random(-3, 4);
lightersSpeed[0][i] = constrain(lightersSpeed[0][i], -20, 20);
@@ -267,11 +315,13 @@ void lightersRoutine() {
if (lightersPos[0][i] < 0) lightersPos[0][i] = (WIDTH - 1) * 10;
if (lightersPos[0][i] >= WIDTH * 10) lightersPos[0][i] = 0;
if (lightersPos[1][i] < 0) {
if (lightersPos[1][i] < 0)
{
lightersPos[1][i] = 0;
lightersSpeed[1][i] = -lightersSpeed[1][i];
}
if (lightersPos[1][i] >= (HEIGHT - 1) * 10) {
if (lightersPos[1][i] >= (HEIGHT - 1) * 10)
{
lightersPos[1][i] = (HEIGHT - 1) * 10;
lightersSpeed[1][i] = -lightersSpeed[1][i];
}
@@ -280,11 +330,14 @@ void lightersRoutine() {
}
/*
void lightersRoutine() {
if (loadingFlag) {
void lightersRoutine()
{
if (loadingFlag)
{
loadingFlag = false;
randomSeed(millis());
for (byte i = 0; i < LIGHTERS_AM; i++) {
for (byte i = 0; i < LIGHTERS_AM; i++)
{
lightersPos[0][i] = random(0, WIDTH * 10);
lightersPos[1][i] = random(0, HEIGHT * 10);
@@ -298,8 +351,10 @@ void lightersRoutine() {
FastLED.clear();
if (++loopCounter > 20) loopCounter = 0;
for (byte i = 0; i < modes[17].scale; i++) {
if (loopCounter == 0) { // меняем скорость каждые 255 отрисовок
for (byte i = 0; i < modes[17].scale; i++)
{
if (loopCounter == 0) // меняем скорость каждые 255 отрисовок
{
angleSpeed[i] += random(-3, 4);
angleSpeed[i] = constrain(angleSpeed[i], -15, 15);
}
@@ -310,17 +365,23 @@ void lightersRoutine() {
if (lightersPos[0][i] < 0) lightersPos[0][i] = (WIDTH - 1) * 10;
if (lightersPos[0][i] >= WIDTH * 10) lightersPos[0][i] = 0;
if (lightersPos[1][i] < 0) {
if (lightersPos[1][i] < 0)
{
lightersPos[1][i] = 0;
angle[i] = 360 - angle[i];
} else {
}
else
{
angle[i] += angleSpeed[i];
}
if (lightersPos[1][i] >= (HEIGHT - 1) * 10) {
if (lightersPos[1][i] >= (HEIGHT - 1) * 10)
{
lightersPos[1][i] = (HEIGHT - 1) * 10;
angle[i] = 360 - angle[i];
} else {
}
else
{
angle[i] += angleSpeed[i];
}
@@ -329,5 +390,5 @@ void lightersRoutine() {
drawPixelXY(lightersPos[0][i] / 10, lightersPos[1][i] / 10, lightersColor[i]);
}
}
}
*/