mirror of
https://github.com/gunner47/GyverLamp.git
synced 2025-08-08 09:20:59 +03:00
Добавлена возможность смены ESP_MODE без перепрошивки; доработан будильник; добавлена визуальная сигнализация красными и жёлтыми вспышками для некоторых действий/состояний; оптимизирован код, исправлены ошибки
This commit is contained in:
@@ -6,11 +6,11 @@ void sparklesRoutine()
|
||||
{
|
||||
for (uint8_t i = 0; i < modes[EFF_SPARKLES].Scale; i++)
|
||||
{
|
||||
uint8_t x = random(0, WIDTH);
|
||||
uint8_t y = random(0, HEIGHT);
|
||||
if (getPixColorXY(x, y) == 0)
|
||||
uint8_t x = random(0U, WIDTH);
|
||||
uint8_t y = random(0U, HEIGHT);
|
||||
if (getPixColorXY(x, y) == 0U)
|
||||
{
|
||||
leds[getPixelNumber(x, y)] = CHSV(random(0, 255), 255, 255);
|
||||
leds[getPixelNumber(x, y)] = CHSV(random(0U, 255U), 255U, 255U);
|
||||
}
|
||||
}
|
||||
fader(FADE_OUT_SPEED);
|
||||
@@ -19,9 +19,9 @@ void sparklesRoutine()
|
||||
// функция плавного угасания цвета для всех пикселей
|
||||
void fader(uint8_t step)
|
||||
{
|
||||
for (uint8_t i = 0; i < WIDTH; i++)
|
||||
for (uint8_t i = 0U; i < WIDTH; i++)
|
||||
{
|
||||
for (uint8_t j = 0; j < HEIGHT; j++)
|
||||
for (uint8_t j = 0U; j < HEIGHT; j++)
|
||||
{
|
||||
fadePixel(i, j, step);
|
||||
}
|
||||
@@ -31,24 +31,24 @@ void fader(uint8_t step)
|
||||
void fadePixel(uint8_t i, uint8_t j, uint8_t step) // новый фейдер
|
||||
{
|
||||
int32_t pixelNum = getPixelNumber(i, j);
|
||||
if (getPixColor(pixelNum) == 0) return;
|
||||
if (getPixColor(pixelNum) == 0U) return;
|
||||
|
||||
if (leds[pixelNum].r >= 30 ||
|
||||
leds[pixelNum].g >= 30 ||
|
||||
leds[pixelNum].b >= 30)
|
||||
if (leds[pixelNum].r >= 30U ||
|
||||
leds[pixelNum].g >= 30U ||
|
||||
leds[pixelNum].b >= 30U)
|
||||
{
|
||||
leds[pixelNum].fadeToBlackBy(step);
|
||||
}
|
||||
else
|
||||
{
|
||||
leds[pixelNum] = 0;
|
||||
leds[pixelNum] = 0U;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------- огонь -----------------
|
||||
#define SPARKLES (1U) // вылетающие угольки вкл выкл
|
||||
uint8_t line[WIDTH];
|
||||
uint8_t pcnt = 0;
|
||||
uint8_t pcnt = 0U;
|
||||
|
||||
//these values are substracetd from the generated values to give a shape to the animation
|
||||
static const uint8_t valueMask[8][16] PROGMEM =
|
||||
@@ -99,7 +99,7 @@ void fireRoutine()
|
||||
// Randomly generate the next line (matrix row)
|
||||
void generateLine()
|
||||
{
|
||||
for (uint8_t x = 0; x < WIDTH; x++)
|
||||
for (uint8_t x = 0U; x < WIDTH; x++)
|
||||
{
|
||||
line[x] = random(64, 255);
|
||||
}
|
||||
@@ -107,22 +107,22 @@ void generateLine()
|
||||
|
||||
void shiftUp()
|
||||
{
|
||||
for (uint8_t y = HEIGHT - 1; y > 0; y--)
|
||||
for (uint8_t y = HEIGHT - 1U; y > 0U; y--)
|
||||
{
|
||||
for (uint8_t x = 0; x < WIDTH; x++)
|
||||
for (uint8_t x = 0U; x < WIDTH; x++)
|
||||
{
|
||||
uint8_t newX = x;
|
||||
if (x > 15) newX = x % 16;
|
||||
if (y > 7) continue;
|
||||
matrixValue[y][newX] = matrixValue[y - 1][newX];
|
||||
if (x > 15U) newX = x % 16U;
|
||||
if (y > 7U) continue;
|
||||
matrixValue[y][newX] = matrixValue[y - 1U][newX];
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t x = 0; x < WIDTH; x++)
|
||||
for (uint8_t x = 0U; x < WIDTH; x++)
|
||||
{
|
||||
uint8_t newX = x;
|
||||
if (x > 15) newX = x % 16;
|
||||
matrixValue[0][newX] = line[newX];
|
||||
if (x > 15U) newX = x % 16U;
|
||||
matrixValue[0U][newX] = line[newX];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,13 +134,13 @@ void drawFrame(uint8_t pcnt)
|
||||
int32_t nextv;
|
||||
|
||||
//each row interpolates with the one before it
|
||||
for (uint8_t y = HEIGHT - 1; y > 0; y--)
|
||||
for (uint8_t y = HEIGHT - 1U; y > 0U; y--)
|
||||
{
|
||||
for (uint8_t x = 0; x < WIDTH; x++)
|
||||
for (uint8_t x = 0U; x < WIDTH; x++)
|
||||
{
|
||||
uint8_t newX = x;
|
||||
if (x > 15) newX = x % 16;
|
||||
if (y < 8)
|
||||
if (x > 15U) newX = x % 16U;
|
||||
if (y < 8U)
|
||||
{
|
||||
nextv =
|
||||
(((100.0 - pcnt) * matrixValue[y][newX]
|
||||
@@ -149,32 +149,32 @@ void drawFrame(uint8_t pcnt)
|
||||
|
||||
CRGB color = CHSV(
|
||||
modes[EFF_FIRE].Scale * 2.5 + pgm_read_byte(&hueMask[y][newX]), // H
|
||||
255, // S
|
||||
255U, // S
|
||||
(uint8_t)max(0, nextv) // V
|
||||
);
|
||||
|
||||
leds[getPixelNumber(x, y)] = color;
|
||||
}
|
||||
else if (y == 8 && SPARKLES)
|
||||
else if (y == 8U && SPARKLES)
|
||||
{
|
||||
if (random(0, 20) == 0 && getPixColorXY(x, y - 1) != 0) drawPixelXY(x, y, getPixColorXY(x, y - 1));
|
||||
else drawPixelXY(x, y, 0);
|
||||
if (random(0, 20) == 0 && getPixColorXY(x, y - 1U) != 0U) drawPixelXY(x, y, getPixColorXY(x, y - 1U));
|
||||
else drawPixelXY(x, y, 0U);
|
||||
}
|
||||
else if (SPARKLES)
|
||||
{
|
||||
// старая версия для яркости
|
||||
if (getPixColorXY(x, y - 1) > 0)
|
||||
drawPixelXY(x, y, getPixColorXY(x, y - 1));
|
||||
else drawPixelXY(x, y, 0);
|
||||
if (getPixColorXY(x, y - 1U) > 0U)
|
||||
drawPixelXY(x, y, getPixColorXY(x, y - 1U));
|
||||
else drawPixelXY(x, y, 0U);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//first row interpolates with the "next" line
|
||||
for (uint8_t x = 0; x < WIDTH; x++)
|
||||
for (uint8_t x = 0U; x < WIDTH; x++)
|
||||
{
|
||||
uint8_t newX = x;
|
||||
if (x > 15) newX = x % 16;
|
||||
if (x > 15U) newX = x % 16U;
|
||||
CRGB color = CHSV(
|
||||
modes[EFF_FIRE].Scale * 2.5 + pgm_read_byte(&(hueMask[0][newX])), // H
|
||||
255, // S
|
||||
@@ -193,7 +193,7 @@ void rainbowVerticalRoutine()
|
||||
for (uint8_t j = 0; j < HEIGHT; j++)
|
||||
{
|
||||
CHSV thisColor = CHSV((uint8_t)(hue + j * modes[EFF_RAINBOW_VER].Scale), 255, 255);
|
||||
for (uint8_t i = 0; i < WIDTH; i++)
|
||||
for (uint8_t i = 0U; i < WIDTH; i++)
|
||||
{
|
||||
drawPixelXY(i, j, thisColor);
|
||||
}
|
||||
@@ -204,10 +204,10 @@ void rainbowVerticalRoutine()
|
||||
void rainbowHorizontalRoutine()
|
||||
{
|
||||
hue += 4;
|
||||
for (uint8_t i = 0; i < WIDTH; i++)
|
||||
for (uint8_t i = 0U; i < WIDTH; i++)
|
||||
{
|
||||
CHSV thisColor = CHSV((uint8_t)(hue + i * modes[EFF_RAINBOW_HOR].Scale), 255, 255);
|
||||
for (uint8_t j = 0; j < HEIGHT; j++)
|
||||
for (uint8_t j = 0U; j < HEIGHT; j++)
|
||||
{
|
||||
drawPixelXY(i, j, thisColor);
|
||||
}
|
||||
@@ -224,12 +224,12 @@ void rainbowDiagonalRoutine()
|
||||
}
|
||||
|
||||
hue += 8;
|
||||
for (uint8_t i = 0; i < WIDTH; i++)
|
||||
for (uint8_t i = 0U; i < WIDTH; i++)
|
||||
{
|
||||
for (uint8_t j = 0; j < HEIGHT; j++)
|
||||
for (uint8_t j = 0U; j < HEIGHT; j++)
|
||||
{
|
||||
float twirlFactor = 3.0F * (modes[EFF_RAINBOW_DIAG].Scale / 100.0F); // на сколько оборотов будет закручена матрица, [0..3]
|
||||
CRGB thisColor = CHSV(constrain((uint8_t)(hue + (float)(WIDTH / HEIGHT * i + j * twirlFactor) * (float)(255 / maxDim)), 0, 255), 255, 255);
|
||||
CRGB thisColor = CHSV(constrain(hue + (float)(WIDTH / HEIGHT * i + j * twirlFactor) * (float)(255 / maxDim), 0, 255), 255, 255);
|
||||
drawPixelXY(i, j, thisColor);
|
||||
}
|
||||
}
|
||||
@@ -242,9 +242,9 @@ void colorsRoutine()
|
||||
{
|
||||
hue += modes[EFF_COLORS].Scale;
|
||||
|
||||
for (int16_t i = 0; i < NUM_LEDS; i++)
|
||||
for (uint16_t i = 0U; i < NUM_LEDS; i++)
|
||||
{
|
||||
leds[i] = CHSV(hue, 255, 255);
|
||||
leds[i] = CHSV(hue, 255U, 255U);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -257,9 +257,9 @@ void colorRoutine()
|
||||
loadingFlag = false;
|
||||
FastLED.clear();
|
||||
|
||||
for (int16_t i = 0; i < NUM_LEDS; i++)
|
||||
for (int16_t i = 0U; i < NUM_LEDS; i++)
|
||||
{
|
||||
leds[i] = CHSV(modes[EFF_COLOR].Scale * 2.5, 255, 255);
|
||||
leds[i] = CHSV(modes[EFF_COLOR].Scale * 2.5, 255U, 255U);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -268,22 +268,22 @@ void colorRoutine()
|
||||
void snowRoutine()
|
||||
{
|
||||
// сдвигаем всё вниз
|
||||
for (uint8_t x = 0; x < WIDTH; x++)
|
||||
for (uint8_t x = 0U; x < WIDTH; x++)
|
||||
{
|
||||
for (uint8_t y = 0; y < HEIGHT - 1; y++)
|
||||
for (uint8_t y = 0U; y < HEIGHT - 1; y++)
|
||||
{
|
||||
drawPixelXY(x, y, getPixColorXY(x, y + 1));
|
||||
drawPixelXY(x, y, getPixColorXY(x, y + 1U));
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t x = 0; x < WIDTH; x++)
|
||||
for (uint8_t x = 0U; x < WIDTH; x++)
|
||||
{
|
||||
// заполняем случайно верхнюю строку
|
||||
// а также не даём двум блокам по вертикали вместе быть
|
||||
if (getPixColorXY(x, HEIGHT - 2) == 0 && (random(0, 100 - modes[EFF_SNOW].Scale) == 0))
|
||||
drawPixelXY(x, HEIGHT - 1, 0xE0FFFF - 0x101010 * random(0, 4));
|
||||
if (getPixColorXY(x, HEIGHT - 2U) == 0U && (random(0, 100 - modes[EFF_SNOW].Scale) == 0U))
|
||||
drawPixelXY(x, HEIGHT - 1U, 0xE0FFFF - 0x101010 * random(0, 4));
|
||||
else
|
||||
drawPixelXY(x, HEIGHT - 1, 0x000000);
|
||||
drawPixelXY(x, HEIGHT - 1U, 0x000000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,45 +300,45 @@ void snowStormRoutine()
|
||||
}
|
||||
|
||||
// заполняем головами комет левую и верхнюю линию
|
||||
for (uint8_t i = HEIGHT / 2; i < HEIGHT; i++)
|
||||
for (uint8_t i = HEIGHT / 2U; i < HEIGHT; i++)
|
||||
{
|
||||
if (getPixColorXY(0, i) == 0 &&
|
||||
if (getPixColorXY(0U, i) == 0U &&
|
||||
(random(0, SNOW_DENSE) == 0) &&
|
||||
getPixColorXY(0, i + 1) == 0 &&
|
||||
getPixColorXY(0, i - 1) == 0)
|
||||
getPixColorXY(0U, i + 1U) == 0U &&
|
||||
getPixColorXY(0U, i - 1U) == 0U)
|
||||
{
|
||||
leds[getPixelNumber(0, i)] = CHSV(random(0, 200), SNOW_SATURATION, 255);
|
||||
leds[getPixelNumber(0U, i)] = CHSV(random(0, 200), SNOW_SATURATION, 255U);
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < WIDTH / 2; i++)
|
||||
for (uint8_t i = 0U; i < WIDTH / 2U; i++)
|
||||
{
|
||||
if (getPixColorXY(i, HEIGHT - 1) == 0 &&
|
||||
(random(0, map(modes[EFF_SNOWSTORM].Scale, 0, 255, 10, 120)) == 0) &&
|
||||
getPixColorXY(i + 1, HEIGHT - 1) == 0 &&
|
||||
getPixColorXY(i - 1, HEIGHT - 1) == 0)
|
||||
if (getPixColorXY(i, HEIGHT - 1U) == 0U &&
|
||||
(random(0, map(modes[EFF_SNOWSTORM].Scale, 0U, 255U, 10U, 120U)) == 0U) &&
|
||||
getPixColorXY(i + 1U, HEIGHT - 1U) == 0U &&
|
||||
getPixColorXY(i - 1U, HEIGHT - 1U) == 0U)
|
||||
{
|
||||
leds[getPixelNumber(i, HEIGHT - 1)] = CHSV(random(0, 200), SNOW_SATURATION, 255);
|
||||
leds[getPixelNumber(i, HEIGHT - 1U)] = CHSV(random(0, 200), SNOW_SATURATION, 255U);
|
||||
}
|
||||
}
|
||||
|
||||
// сдвигаем по диагонали
|
||||
for (uint8_t y = 0; y < HEIGHT - 1; y++)
|
||||
for (uint8_t y = 0U; y < HEIGHT - 1U; y++)
|
||||
{
|
||||
for (uint8_t x = WIDTH - 1; x > 0; x--)
|
||||
for (uint8_t x = WIDTH - 1U; x > 0U; x--)
|
||||
{
|
||||
drawPixelXY(x, y, getPixColorXY(x - 1, y + 1));
|
||||
drawPixelXY(x, y, getPixColorXY(x - 1U, y + 1U));
|
||||
}
|
||||
}
|
||||
|
||||
// уменьшаем яркость левой и верхней линии, формируем "хвосты"
|
||||
for (uint8_t i = HEIGHT / 2; i < HEIGHT; i++)
|
||||
for (uint8_t i = HEIGHT / 2U; i < HEIGHT; i++)
|
||||
{
|
||||
fadePixel(0, i, SNOW_TAIL_STEP);
|
||||
fadePixel(0U, i, SNOW_TAIL_STEP);
|
||||
}
|
||||
for (uint8_t i = 0; i < WIDTH / 2; i++)
|
||||
for (uint8_t i = 0U; i < WIDTH / 2U; i++)
|
||||
{
|
||||
fadePixel(i, HEIGHT - 1, SNOW_TAIL_STEP);
|
||||
fadePixel(i, HEIGHT - 1U, SNOW_TAIL_STEP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,77 +355,77 @@ void starfallRoutine()
|
||||
}
|
||||
|
||||
// заполняем головами комет левую и верхнюю линию
|
||||
for (uint8_t i = HEIGHT / 2; i < HEIGHT; i++)
|
||||
for (uint8_t i = HEIGHT / 2U; i < HEIGHT; i++)
|
||||
{
|
||||
if (getPixColorXY(0, i) == 0 &&
|
||||
if (getPixColorXY(0U, i) == 0U &&
|
||||
(random(0, STAR_DENSE) == 0) &&
|
||||
getPixColorXY(0, i + 1) == 0 &&
|
||||
getPixColorXY(0, i - 1) == 0)
|
||||
getPixColorXY(0U, i + 1U) == 0U &&
|
||||
getPixColorXY(0U, i - 1U) == 0U)
|
||||
{
|
||||
leds[getPixelNumber(0, i)] = CHSV(random(0, 200), STAR_SATURATION, 255);
|
||||
leds[getPixelNumber(0U, i)] = CHSV(random(0, 200), STAR_SATURATION, 255U);
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < WIDTH / 2; i++)
|
||||
for (uint8_t i = 0U; i < WIDTH / 2U; i++)
|
||||
{
|
||||
if (getPixColorXY(i, HEIGHT - 1) == 0 &&
|
||||
(random(0, map(modes[EFF_STARFALL].Scale, 0, 255, 10, 120)) == 0) &&
|
||||
getPixColorXY(i + 1, HEIGHT - 1) == 0 &&
|
||||
getPixColorXY(i - 1, HEIGHT - 1) == 0)
|
||||
if (getPixColorXY(i, HEIGHT - 1U) == 0U &&
|
||||
(random(0, map(modes[EFF_STARFALL].Scale, 0U, 255U, 10U, 120U)) == 0U) &&
|
||||
getPixColorXY(i + 1U, HEIGHT - 1U) == 0U &&
|
||||
getPixColorXY(i - 1U, HEIGHT - 1U) == 0U)
|
||||
{
|
||||
leds[getPixelNumber(i, HEIGHT - 1)] = CHSV(random(0, 200), STAR_SATURATION, 255);
|
||||
leds[getPixelNumber(i, HEIGHT - 1U)] = CHSV(random(0, 200), STAR_SATURATION, 255U);
|
||||
}
|
||||
}
|
||||
|
||||
// сдвигаем по диагонали
|
||||
for (uint8_t y = 0; y < HEIGHT - 1; y++)
|
||||
for (uint8_t y = 0U; y < HEIGHT - 1U; y++)
|
||||
{
|
||||
for (uint8_t x = WIDTH - 1; x > 0; x--)
|
||||
for (uint8_t x = WIDTH - 1U; x > 0U; x--)
|
||||
{
|
||||
drawPixelXY(x, y, getPixColorXY(x - 1, y + 1));
|
||||
drawPixelXY(x, y, getPixColorXY(x - 1U, y + 1U));
|
||||
}
|
||||
}
|
||||
|
||||
// уменьшаем яркость левой и верхней линии, формируем "хвосты"
|
||||
for (uint8_t i = HEIGHT / 2; i < HEIGHT; i++)
|
||||
for (uint8_t i = HEIGHT / 2U; i < HEIGHT; i++)
|
||||
{
|
||||
fadePixel(0, i, STAR_TAIL_STEP);
|
||||
fadePixel(0U, i, STAR_TAIL_STEP);
|
||||
}
|
||||
for (uint8_t i = 0; i < WIDTH / 2; i++)
|
||||
for (uint8_t i = 0U; i < WIDTH / 2U; i++)
|
||||
{
|
||||
fadePixel(i, HEIGHT - 1, STAR_TAIL_STEP);
|
||||
fadePixel(i, HEIGHT - 1U, STAR_TAIL_STEP);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------- матрица ---------------
|
||||
void matrixRoutine()
|
||||
{
|
||||
for (uint8_t x = 0; x < WIDTH; x++)
|
||||
for (uint8_t x = 0U; x < WIDTH; x++)
|
||||
{
|
||||
// заполняем случайно верхнюю строку
|
||||
uint32_t thisColor = getPixColorXY(x, HEIGHT - 1);
|
||||
if (thisColor == 0)
|
||||
drawPixelXY(x, HEIGHT - 1, 0x00FF00 * (random(0, 100 - modes[EFF_MATRIX].Scale) == 0));
|
||||
uint32_t thisColor = getPixColorXY(x, HEIGHT - 1U);
|
||||
if (thisColor == 0U)
|
||||
drawPixelXY(x, HEIGHT - 1U, 0x00FF00 * (random(0, 100 - modes[EFF_MATRIX].Scale) == 0U));
|
||||
else if (thisColor < 0x002000)
|
||||
drawPixelXY(x, HEIGHT - 1, 0);
|
||||
drawPixelXY(x, HEIGHT - 1U, 0U);
|
||||
else
|
||||
drawPixelXY(x, HEIGHT - 1, thisColor - 0x002000);
|
||||
drawPixelXY(x, HEIGHT - 1U, thisColor - 0x002000);
|
||||
}
|
||||
|
||||
// сдвигаем всё вниз
|
||||
for (uint8_t x = 0; x < WIDTH; x++)
|
||||
for (uint8_t x = 0U; x < WIDTH; x++)
|
||||
{
|
||||
for (uint8_t y = 0; y < HEIGHT - 1; y++)
|
||||
for (uint8_t y = 0U; y < HEIGHT - 1U; y++)
|
||||
{
|
||||
drawPixelXY(x, y, getPixColorXY(x, y + 1));
|
||||
drawPixelXY(x, y, getPixColorXY(x, y + 1U));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------- светлячки --------------
|
||||
#define LIGHTERS_AM (100)
|
||||
int32_t lightersPos[2][LIGHTERS_AM];
|
||||
int8_t lightersSpeed[2][LIGHTERS_AM];
|
||||
#define LIGHTERS_AM (100U)
|
||||
int32_t lightersPos[2U][LIGHTERS_AM];
|
||||
int8_t lightersSpeed[2U][LIGHTERS_AM];
|
||||
CHSV lightersColor[LIGHTERS_AM];
|
||||
uint8_t loopCounter;
|
||||
int32_t angle[LIGHTERS_AM];
|
||||
@@ -437,44 +437,44 @@ void lightersRoutine()
|
||||
{
|
||||
loadingFlag = false;
|
||||
randomSeed(millis());
|
||||
for (uint8_t i = 0; i < LIGHTERS_AM; i++)
|
||||
for (uint8_t i = 0U; i < LIGHTERS_AM; i++)
|
||||
{
|
||||
lightersPos[0][i] = random(0, WIDTH * 10);
|
||||
lightersPos[1][i] = random(0, HEIGHT * 10);
|
||||
lightersSpeed[0][i] = random(-10, 10);
|
||||
lightersSpeed[1][i] = random(-10, 10);
|
||||
lightersColor[i] = CHSV(random(0, 255), 255, 255);
|
||||
lightersPos[0U][i] = random(0, WIDTH * 10);
|
||||
lightersPos[1U][i] = random(0, HEIGHT * 10);
|
||||
lightersSpeed[0U][i] = random(-10, 10);
|
||||
lightersSpeed[1U][i] = random(-10, 10);
|
||||
lightersColor[i] = CHSV(random(0U, 255U), 255U, 255U);
|
||||
}
|
||||
}
|
||||
FastLED.clear();
|
||||
if (++loopCounter > 20) loopCounter = 0;
|
||||
for (uint8_t i = 0; i < modes[EFF_LIGHTERS].Scale; i++)
|
||||
if (++loopCounter > 20U) loopCounter = 0U;
|
||||
for (uint8_t i = 0U; i < modes[EFF_LIGHTERS].Scale; i++)
|
||||
{
|
||||
if (loopCounter == 0) // меняем скорость каждые 255 отрисовок
|
||||
if (loopCounter == 0U) // меняем скорость каждые 255 отрисовок
|
||||
{
|
||||
lightersSpeed[0][i] += random(-3, 4);
|
||||
lightersSpeed[1][i] += random(-3, 4);
|
||||
lightersSpeed[0][i] = constrain(lightersSpeed[0][i], -20, 20);
|
||||
lightersSpeed[1][i] = constrain(lightersSpeed[1][i], -20, 20);
|
||||
lightersSpeed[0U][i] += random(-3, 4);
|
||||
lightersSpeed[1U][i] += random(-3, 4);
|
||||
lightersSpeed[0U][i] = constrain(lightersSpeed[0U][i], -20, 20);
|
||||
lightersSpeed[1U][i] = constrain(lightersSpeed[1U][i], -20, 20);
|
||||
}
|
||||
|
||||
lightersPos[0][i] += lightersSpeed[0][i];
|
||||
lightersPos[1][i] += lightersSpeed[1][i];
|
||||
lightersPos[0U][i] += lightersSpeed[0U][i];
|
||||
lightersPos[1U][i] += lightersSpeed[1U][i];
|
||||
|
||||
if (lightersPos[0][i] < 0) lightersPos[0][i] = (WIDTH - 1) * 10;
|
||||
if (lightersPos[0][i] >= WIDTH * 10) lightersPos[0][i] = 0;
|
||||
if (lightersPos[0U][i] < 0) lightersPos[0U][i] = (WIDTH - 1) * 10;
|
||||
if (lightersPos[0U][i] >= (int32_t)(WIDTH * 10)) lightersPos[0U][i] = 0;
|
||||
|
||||
if (lightersPos[1][i] < 0)
|
||||
if (lightersPos[1U][i] < 0)
|
||||
{
|
||||
lightersPos[1][i] = 0;
|
||||
lightersSpeed[1][i] = -lightersSpeed[1][i];
|
||||
lightersPos[1U][i] = 0;
|
||||
lightersSpeed[1U][i] = -lightersSpeed[1U][i];
|
||||
}
|
||||
if (lightersPos[1][i] >= (HEIGHT - 1) * 10)
|
||||
if (lightersPos[1U][i] >= (int32_t)(HEIGHT - 1) * 10)
|
||||
{
|
||||
lightersPos[1][i] = (HEIGHT - 1) * 10;
|
||||
lightersSpeed[1][i] = -lightersSpeed[1][i];
|
||||
lightersPos[1U][i] = (HEIGHT - 1U) * 10;
|
||||
lightersSpeed[1U][i] = -lightersSpeed[1U][i];
|
||||
}
|
||||
drawPixelXY(lightersPos[0][i] / 10, lightersPos[1][i] / 10, lightersColor[i]);
|
||||
drawPixelXY(lightersPos[0U][i] / 10, lightersPos[1U][i] / 10, lightersColor[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -483,8 +483,8 @@ void lightersRoutine()
|
||||
#define CLEAR_PATH (1U) // очищать путь
|
||||
#define BALL_TRACK (1U) // (0 / 1) - вкл/выкл следы шариков
|
||||
#define TRACK_STEP (70U) // длина хвоста шарика (чем больше цифра, тем хвост короче)
|
||||
int16_t coord[BALLS_AMOUNT][2];
|
||||
int8_t vector[BALLS_AMOUNT][2];
|
||||
int16_t coord[BALLS_AMOUNT][2U];
|
||||
int8_t vector[BALLS_AMOUNT][2U];
|
||||
CRGB ballColors[BALLS_AMOUNT];
|
||||
void ballsRoutine()
|
||||
{
|
||||
@@ -492,17 +492,17 @@ void ballsRoutine()
|
||||
{
|
||||
loadingFlag = false;
|
||||
|
||||
for (uint8_t j = 0; j < BALLS_AMOUNT; j++)
|
||||
for (uint8_t j = 0U; j < BALLS_AMOUNT; j++)
|
||||
{
|
||||
int8_t sign;
|
||||
// забиваем случайными данными
|
||||
coord[j][0] = WIDTH / 2 * 10;
|
||||
coord[j][0U] = WIDTH / 2 * 10;
|
||||
random(0, 2) ? sign = 1 : sign = -1;
|
||||
vector[j][0] = random(4, 15) * sign;
|
||||
coord[j][1] = HEIGHT / 2 * 10;
|
||||
vector[j][0U] = random(4, 15) * sign;
|
||||
coord[j][1U] = HEIGHT / 2 * 10;
|
||||
random(0, 2) ? sign = 1 : sign = -1;
|
||||
vector[j][1] = random(4, 15) * sign;
|
||||
ballColors[j] = CHSV(random(0, 9) * 28, 255, 255);
|
||||
vector[j][1U] = random(4, 15) * sign;
|
||||
ballColors[j] = CHSV(random(0, 9) * 28, 255U, 255U);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -516,10 +516,10 @@ void ballsRoutine()
|
||||
}
|
||||
|
||||
// движение шариков
|
||||
for (uint8_t j = 0; j < BALLS_AMOUNT; j++)
|
||||
for (uint8_t j = 0U; j < BALLS_AMOUNT; j++)
|
||||
{
|
||||
// движение шариков
|
||||
for (uint8_t i = 0; i < 2; i++)
|
||||
for (uint8_t i = 0U; i < 2U; i++)
|
||||
{
|
||||
coord[j][i] += vector[j][i];
|
||||
if (coord[j][i] < 0)
|
||||
@@ -529,22 +529,22 @@ void ballsRoutine()
|
||||
}
|
||||
}
|
||||
|
||||
if (coord[j][0] > (WIDTH - 1) * 10)
|
||||
if (coord[j][0U] > (int16_t)((WIDTH - 1) * 10))
|
||||
{
|
||||
coord[j][0] = (WIDTH - 1) * 10;
|
||||
vector[j][0] = -vector[j][0];
|
||||
coord[j][0U] = (WIDTH - 1) * 10;
|
||||
vector[j][0U] = -vector[j][0U];
|
||||
}
|
||||
if (coord[j][1] > (HEIGHT - 1) * 10)
|
||||
if (coord[j][1U] > (int16_t)((HEIGHT - 1) * 10))
|
||||
{
|
||||
coord[j][1] = (HEIGHT - 1) * 10;
|
||||
vector[j][1] = -vector[j][1];
|
||||
coord[j][1U] = (HEIGHT - 1) * 10;
|
||||
vector[j][1U] = -vector[j][1U];
|
||||
}
|
||||
leds[getPixelNumber(coord[j][0] / 10, coord[j][1] / 10)] = ballColors[j];
|
||||
leds[getPixelNumber(coord[j][0U] / 10, coord[j][1U] / 10)] = ballColors[j];
|
||||
}
|
||||
}
|
||||
|
||||
// ------------- пейнтбол -------------
|
||||
const uint8_t BorderWidth = 2;
|
||||
const uint8_t BorderWidth = 2U;
|
||||
void lightBallsRoutine()
|
||||
{
|
||||
// Apply some blurring to whatever's already on the matrix
|
||||
@@ -562,10 +562,10 @@ void lightBallsRoutine()
|
||||
|
||||
// The color of each point shifts over time, each at a different speed.
|
||||
uint16_t ms = millis();
|
||||
leds[XY( i, j)] += CHSV( ms / 29, 200, 255);
|
||||
leds[XY( j, k)] += CHSV( ms / 41, 200, 255);
|
||||
leds[XY( k, m)] += CHSV( ms / 73, 200, 255);
|
||||
leds[XY( m, i)] += CHSV( ms / 97, 200, 255);
|
||||
leds[XY( i, j)] += CHSV( ms / 29, 200U, 255U);
|
||||
leds[XY( j, k)] += CHSV( ms / 41, 200U, 255U);
|
||||
leds[XY( k, m)] += CHSV( ms / 73, 200U, 255U);
|
||||
leds[XY( m, i)] += CHSV( ms / 97, 200U, 255U);
|
||||
|
||||
}
|
||||
// Trivial XY function for the SmartMatrix; use a different XY
|
||||
@@ -589,8 +589,8 @@ uint16_t XY(uint8_t x, uint8_t y)
|
||||
|
||||
// ------------- блуждающий кубик -------------
|
||||
#define RANDOM_COLOR (1U) // случайный цвет при отскоке
|
||||
int16_t coordB[2];
|
||||
int8_t vectorB[2];
|
||||
int16_t coordB[2U];
|
||||
int8_t vectorB[2U];
|
||||
CRGB ballColor;
|
||||
int8_t ballSize;
|
||||
void ballRoutine()
|
||||
@@ -600,49 +600,49 @@ void ballRoutine()
|
||||
loadingFlag = false;
|
||||
//FastLED.clear();
|
||||
|
||||
for (uint8_t i = 0; i < 2; i++)
|
||||
for (uint8_t i = 0U; i < 2U; i++)
|
||||
{
|
||||
coordB[i] = WIDTH / 2 * 10;
|
||||
vectorB[i] = random(8, 20);
|
||||
ballColor = CHSV(random(0, 9) * 28, 255, 255);
|
||||
ballColor = CHSV(random(0, 9) * 28, 255U, 255U);
|
||||
}
|
||||
}
|
||||
|
||||
ballSize = map(modes[EFF_CUBE].Scale, 0, 255, 2, max((int16_t)min(WIDTH,HEIGHT) / 3, 2));
|
||||
for (uint8_t i = 0; i < 2; i++)
|
||||
ballSize = map(modes[EFF_CUBE].Scale, 0U, 255U, 2U, max((uint8_t)min(WIDTH,HEIGHT) / 3, 2));
|
||||
for (uint8_t i = 0U; i < 2U; i++)
|
||||
{
|
||||
coordB[i] += vectorB[i];
|
||||
if (coordB[i] < 0)
|
||||
{
|
||||
coordB[i] = 0;
|
||||
vectorB[i] = -vectorB[i];
|
||||
if (RANDOM_COLOR) ballColor = CHSV(random(0, 9) * 28, 255, 255);
|
||||
if (RANDOM_COLOR) ballColor = CHSV(random(0, 9) * 28, 255U, 255U);
|
||||
//vectorB[i] += random(0, 6) - 3;
|
||||
}
|
||||
}
|
||||
if (coordB[0] > (WIDTH - ballSize) * 10)
|
||||
if (coordB[0U] > (int16_t)((WIDTH - ballSize) * 10))
|
||||
{
|
||||
coordB[0] = (WIDTH - ballSize) * 10;
|
||||
vectorB[0] = -vectorB[0];
|
||||
if (RANDOM_COLOR) ballColor = CHSV(random(0, 9) * 28, 255, 255);
|
||||
coordB[0U] = (WIDTH - ballSize) * 10;
|
||||
vectorB[0U] = -vectorB[0U];
|
||||
if (RANDOM_COLOR) ballColor = CHSV(random(0, 9) * 28, 255U, 255U);
|
||||
//vectorB[0] += random(0, 6) - 3;
|
||||
}
|
||||
if (coordB[1] > (HEIGHT - ballSize) * 10)
|
||||
if (coordB[1U] > (int16_t)((HEIGHT - ballSize) * 10))
|
||||
{
|
||||
coordB[1] = (HEIGHT - ballSize) * 10;
|
||||
vectorB[1] = -vectorB[1];
|
||||
coordB[1U] = (HEIGHT - ballSize) * 10;
|
||||
vectorB[1U] = -vectorB[1U];
|
||||
if (RANDOM_COLOR)
|
||||
{
|
||||
ballColor = CHSV(random(0, 9) * 28, 255, 255);
|
||||
ballColor = CHSV(random(0, 9) * 28, 255U, 255U);
|
||||
}
|
||||
//vectorB[1] += random(0, 6) - 3;
|
||||
}
|
||||
FastLED.clear();
|
||||
for (uint8_t i = 0; i < ballSize; i++)
|
||||
for (uint8_t i = 0U; i < ballSize; i++)
|
||||
{
|
||||
for (uint8_t j = 0; j < ballSize; j++)
|
||||
for (uint8_t j = 0U; j < ballSize; j++)
|
||||
{
|
||||
leds[getPixelNumber(coordB[0] / 10 + i, coordB[1] / 10 + j)] = ballColor;
|
||||
leds[getPixelNumber(coordB[0U] / 10 + i, coordB[1U] / 10 + j)] = ballColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -655,9 +655,9 @@ void whiteColorRoutine()
|
||||
loadingFlag = false;
|
||||
FastLED.clear();
|
||||
|
||||
for (int16_t i = 0; i < NUM_LEDS; i++)
|
||||
for (uint16_t i = 0U; i < NUM_LEDS; i++)
|
||||
{
|
||||
leds[i] = CHSV(0, 0, 255);
|
||||
leds[i] = CHSV(0U, 0U, 255U);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -676,82 +676,57 @@ void whiteColorStripeRoutine()
|
||||
for (int16_t y = centerY; y >= 0; y--)
|
||||
{
|
||||
CRGB color = CHSV(
|
||||
45, // определяем тон
|
||||
map(modes[EFF_WHITE_COLOR].Speed, 0, 255, 0, 170), // определяем насыщенность
|
||||
45U, // определяем тон
|
||||
map(modes[EFF_WHITE_COLOR].Speed, 0U, 255U, 0U, 170U), // определяем насыщенность
|
||||
y == centerY // определяем яркость
|
||||
? 255 // для центральной горизонтальной полосы (или двух) яркость всегда равна 255
|
||||
: (modes[EFF_WHITE_COLOR].Scale / 100.0F) > ((centerY + 1.0F) - (y + 1.0F)) / (centerY + 1.0F) ? 255 : 0); // для остальных горизонтальных полос яркость равна либо 255, либо 0 в зависимости от масштаба
|
||||
? 255U // для центральной горизонтальной полосы (или двух) яркость всегда равна 255
|
||||
: (modes[EFF_WHITE_COLOR].Scale / 100.0F) > ((centerY + 1.0F) - (y + 1.0F)) / (centerY + 1.0F) ? 255U : 0U); // для остальных горизонтальных полос яркость равна либо 255, либо 0 в зависимости от масштаба
|
||||
|
||||
for (uint8_t x = 0; x < WIDTH; x++)
|
||||
for (uint8_t x = 0U; x < WIDTH; x++)
|
||||
{
|
||||
drawPixelXY(x, y, color); // при чётной высоте матрицы максимально яркими отрисуются 2 центральных горизонтальных полосы
|
||||
drawPixelXY(x, max((uint8_t)(HEIGHT - 1) - (y + 1) + bottomOffset, 0), color); // при нечётной - одна, но дважды
|
||||
drawPixelXY(x, max((uint8_t)(HEIGHT - 1U) - (y + 1U) + bottomOffset, 0U), color); // при нечётной - одна, но дважды
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* устарело
|
||||
void lightersRoutine()
|
||||
// ------------- мигающий цвет (не эффект! используется для отображения краткосрочного предупреждения; блокирующий код!) -------------
|
||||
#define WARNING_BRIGHTNESS (10U) // яркость вспышки
|
||||
void showWarning(
|
||||
CRGB color, // цвет вспышки
|
||||
uint32_t duration, // продолжительность отображения предупреждения (общее время)
|
||||
uint16_t blinkHalfPeriod) // продолжительность одной вспышки в миллисекундах (полупериод)
|
||||
{
|
||||
if (loadingFlag)
|
||||
{
|
||||
loadingFlag = false;
|
||||
randomSeed(millis());
|
||||
for (uint8_t i = 0; i < LIGHTERS_AM; i++)
|
||||
{
|
||||
lightersPos[0][i] = random(0, WIDTH * 10);
|
||||
lightersPos[1][i] = random(0, HEIGHT * 10);
|
||||
|
||||
lightersColor[i] = CHSV(random(0, 255), 255, 255);
|
||||
|
||||
speedV[i] = random(5, 10);
|
||||
angle[i] = random(0, 360);
|
||||
angleSpeed[i] = random(-10, 10);
|
||||
}
|
||||
}
|
||||
uint32_t blinkTimer = millis();
|
||||
enum BlinkState { OFF = 0, ON = 1 } blinkState = BlinkState::OFF;
|
||||
FastLED.setBrightness(WARNING_BRIGHTNESS); // установка яркости для предупреждения
|
||||
FastLED.clear();
|
||||
if (++loopCounter > 20) loopCounter = 0;
|
||||
delay(2);
|
||||
FastLED.show();
|
||||
|
||||
for (uint8_t i = 0; i < modes[EFF_LIGHTER_TRACES].scale; i++)
|
||||
for (uint16_t i = 0U; i < NUM_LEDS; i++) // установка цвета всех диодов в WARNING_COLOR
|
||||
{
|
||||
if (loopCounter == 0) // меняем скорость каждые 255 отрисовок
|
||||
{
|
||||
angleSpeed[i] += random(-3, 4);
|
||||
angleSpeed[i] = constrain(angleSpeed[i], -15, 15);
|
||||
}
|
||||
|
||||
lightersPos[0][i] += speedV[i] * cos(radians(angle[i]));
|
||||
lightersPos[1][i] += speedV[i] * sin(radians(angle[i]));
|
||||
|
||||
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)
|
||||
{
|
||||
lightersPos[1][i] = 0;
|
||||
angle[i] = 360 - angle[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
angle[i] += angleSpeed[i];
|
||||
}
|
||||
|
||||
if (lightersPos[1][i] >= (HEIGHT - 1) * 10)
|
||||
{
|
||||
lightersPos[1][i] = (HEIGHT - 1) * 10;
|
||||
angle[i] = 360 - angle[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
angle[i] += angleSpeed[i];
|
||||
}
|
||||
|
||||
if (angle[i] > 360) angle[i] = 360 - angle[i];
|
||||
if (angle[i] < 0) angle[i] = 360 + angle[i];
|
||||
|
||||
drawPixelXY(lightersPos[0][i] / 10, lightersPos[1][i] / 10, lightersColor[i]);
|
||||
leds[i] = color;
|
||||
}
|
||||
|
||||
uint32_t startTime = millis();
|
||||
while (millis() - startTime <= (duration + 5)) // блокировка дальнейшего выполнения циклом на время отображения предупреждения
|
||||
{
|
||||
if (millis() - blinkTimer >= blinkHalfPeriod) // переключение вспышка/темнота
|
||||
{
|
||||
blinkTimer = millis();
|
||||
blinkState = (BlinkState)!blinkState;
|
||||
FastLED.setBrightness(blinkState == BlinkState::OFF ? 0 : WARNING_BRIGHTNESS);
|
||||
delay(1);
|
||||
FastLED.show();
|
||||
}
|
||||
delay(50);
|
||||
}
|
||||
|
||||
FastLED.clear();
|
||||
FastLED.setBrightness(ONflag ? modes[currentMode].Brightness : 0); // установка яркости, которая была выставлена до вызова предупреждения
|
||||
delay(1);
|
||||
FastLED.show();
|
||||
loadingFlag = true; // принудительное отображение текущего эффекта (того, что был активен перед предупреждением)
|
||||
}
|
||||
*/
|
||||
|
Reference in New Issue
Block a user