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,4 +1,4 @@
// ******************* НАСТРОЙКИ *****************
// ************* НАСТРОЙКИ *************
// "масштаб" эффектов. Чем меньше, тем крупнее!
#define MADNESS_SCALE 100
#define CLOUD_SCALE 30
@@ -10,15 +10,15 @@
#define FOREST_SCALE 120
#define OCEAN_SCALE 90
// ***************** ДЛЯ РАЗРАБОТЧИКОВ ******************
// ************* ДЛЯ РАЗРАБОТЧИКОВ *****
// The 16 bit version of our coordinates
static uint16_t x;
static uint16_t y;
static uint16_t z;
uint16_t speed = 20; // speed is set dynamically once we've started up
uint16_t scale = 30; // scale is set dynamically once we've started up
uint16_t speed = 20; // speed is set dynamically once we've started up
uint16_t scale = 30; // scale is set dynamically once we've started up
// This is the array that we keep our computed noise values in
#define MAX_DIMENSION (max(WIDTH, HEIGHT))
@@ -32,23 +32,30 @@ CRGBPalette16 currentPalette( PartyColors_p );
uint8_t colorLoop = 1;
uint8_t ihue = 0;
void madnessNoise() {
if (loadingFlag) {
void madnessNoise()
{
if (loadingFlag)
{
loadingFlag = false;
scale = modes[5].scale;
speed = modes[5].speed;
}
fillnoise8();
for (int i = 0; i < WIDTH; i++) {
for (int j = 0; j < HEIGHT; j++) {
for (uint8_t i = 0; i < WIDTH; i++)
{
for (uint8_t j = 0; j < HEIGHT; j++)
{
CRGB thisColor = CHSV(noise[j][i], 255, noise[i][j]);
drawPixelXY(i, j, thisColor); //leds[getPixelNumber(i, j)] = CHSV(noise[j][i], 255, noise[i][j]);
drawPixelXY(i, j, thisColor); //leds[getPixelNumber(i, j)] = CHSV(noise[j][i], 255, noise[i][j]);
}
}
ihue += 1;
}
void rainbowNoise() {
if (loadingFlag) {
void rainbowNoise()
{
if (loadingFlag)
{
loadingFlag = false;
currentPalette = RainbowColors_p;
scale = modes[9].scale;
@@ -57,8 +64,11 @@ void rainbowNoise() {
}
fillNoiseLED();
}
void rainbowStripeNoise() {
if (loadingFlag) {
void rainbowStripeNoise()
{
if (loadingFlag)
{
loadingFlag = false;
currentPalette = RainbowStripeColors_p;
scale = modes[10].scale;
@@ -67,8 +77,11 @@ void rainbowStripeNoise() {
}
fillNoiseLED();
}
void zebraNoise() {
if (loadingFlag) {
void zebraNoise()
{
if (loadingFlag)
{
loadingFlag = false;
// 'black out' all 16 palette entries...
fill_solid( currentPalette, 16, CRGB::Black);
@@ -83,8 +96,11 @@ void zebraNoise() {
}
fillNoiseLED();
}
void forestNoise() {
if (loadingFlag) {
void forestNoise()
{
if (loadingFlag)
{
loadingFlag = false;
currentPalette = ForestColors_p;
scale = modes[12].scale;
@@ -93,8 +109,11 @@ void forestNoise() {
}
fillNoiseLED();
}
void oceanNoise() {
if (loadingFlag) {
void oceanNoise()
{
if (loadingFlag)
{
loadingFlag = false;
currentPalette = OceanColors_p;
scale = modes[13].scale;
@@ -104,8 +123,11 @@ void oceanNoise() {
fillNoiseLED();
}
void plasmaNoise() {
if (loadingFlag) {
void plasmaNoise()
{
if (loadingFlag)
{
loadingFlag = false;
currentPalette = PartyColors_p;
scale = modes[8].scale;
@@ -114,8 +136,11 @@ void plasmaNoise() {
}
fillNoiseLED();
}
void cloudNoise() {
if (loadingFlag) {
void cloudNoise()
{
if (loadingFlag)
{
loadingFlag = false;
currentPalette = CloudColors_p;
scale = modes[6].scale;
@@ -124,8 +149,11 @@ void cloudNoise() {
}
fillNoiseLED();
}
void lavaNoise() {
if (loadingFlag) {
void lavaNoise()
{
if (loadingFlag)
{
loadingFlag = false;
currentPalette = LavaColors_p;
scale = modes[7].scale;
@@ -135,23 +163,28 @@ void lavaNoise() {
fillNoiseLED();
}
// ******************* СЛУЖЕБНЫЕ *******************
void fillNoiseLED() {
// ************* СЛУЖЕБНЫЕ *************
void fillNoiseLED()
{
uint8_t dataSmoothing = 0;
if ( speed < 50) {
if ( speed < 50)
{
dataSmoothing = 200 - (speed * 4);
}
for (int i = 0; i < MAX_DIMENSION; i++) {
int ioffset = scale * i;
for (int j = 0; j < MAX_DIMENSION; j++) {
int joffset = scale * j;
for (uint8_t i = 0; i < MAX_DIMENSION; i++)
{
int32_t ioffset = scale * i;
for (uint8_t j = 0; j < MAX_DIMENSION; j++)
{
int32_t joffset = scale * j;
uint8_t data = inoise8(x + ioffset, y + joffset, z);
data = qsub8(data, 16);
data = qadd8(data, scale8(data, 39));
if ( dataSmoothing ) {
if ( dataSmoothing )
{
uint8_t olddata = noise[i][j];
uint8_t newdata = scale8( olddata, dataSmoothing) + scale8( data, 256 - dataSmoothing);
data = newdata;
@@ -166,33 +199,42 @@ void fillNoiseLED() {
x += speed / 8;
y -= speed / 16;
for (int i = 0; i < WIDTH; i++) {
for (int j = 0; j < HEIGHT; j++) {
for (uint8_t i = 0; i < WIDTH; i++)
{
for (uint8_t j = 0; j < HEIGHT; j++)
{
uint8_t index = noise[j][i];
uint8_t bri = noise[i][j];
// if this palette is a 'loop', add a slowly-changing base value
if ( colorLoop) {
if ( colorLoop)
{
index += ihue;
}
// brighten up, as the color palette itself often contains the
// light/dark dynamic range desired
if ( bri > 127 ) {
if ( bri > 127 )
{
bri = 255;
} else {
}
else
{
bri = dim8_raw( bri * 2);
}
CRGB color = ColorFromPalette( currentPalette, index, bri);
drawPixelXY(i, j, color); //leds[getPixelNumber(i, j)] = color;
drawPixelXY(i, j, color); //leds[getPixelNumber(i, j)] = color;
}
}
ihue += 1;
}
void fillnoise8() {
for (int i = 0; i < MAX_DIMENSION; i++) {
int ioffset = scale * i;
for (int j = 0; j < MAX_DIMENSION; j++) {
int joffset = scale * j;
void fillnoise8()
{
for (uint8_t i = 0; i < MAX_DIMENSION; i++)
{
int32_t ioffset = scale * i;
for (uint8_t j = 0; j < MAX_DIMENSION; j++)
{
int32_t joffset = scale * j;
noise[i][j] = inoise8(x + ioffset, y + joffset, z);
}
}