From be63505d2298e091cf6d4e2e24a1dff22ccefc79 Mon Sep 17 00:00:00 2001 From: Armin Date: Tue, 15 Dec 2020 20:04:41 +0100 Subject: [PATCH] Changed fire cooling --- README.md | 9 +++++---- examples/AllPatternsOnMultiDevices/ADCUtils.cpp | 2 +- examples/AllPatternsOnMultiDevices/ADCUtils.h | 5 +++++ examples/MatrixFire/MatrixFire.ino | 13 +++++++------ src/Colors.h | 4 ++++ src/MatrixNeoPatterns.cpp | 9 ++++++--- src/MatrixNeoPatterns.h | 2 +- src/NeoPatterns.h | 3 ++- 8 files changed, 31 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 1d5c6da..6423ba3 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ New Patterns are added, a snake game running on a matrix is included and you can | YouTube Video of NeoPatternsDemo | YouTube Video of MatrixDemo on a 10x10 matrix | | :-: | :-: | | [![Demonstration of NeoPatterns](https://i.ytimg.com/vi/CsB7FkywCRQ/hqdefault.jpg)](https://www.youtube.com/watch?v=CsB7FkywCRQ) | [![Demonstration of MatrixDemo on a 10x10 matrix](https://i.ytimg.com/vi/URsq28l2PEQ/hqdefault.jpg)](https://www.youtube.com/watch?v=URsq28l2PEQ) | +| YouTube Video of NeoPatternsDemo on a long matrix | YouTube Video of Fire on on a long matrix | +| [![Demonstration of NeoPatterns on a long matrix ](https://i.ytimg.com/vi/y_fmAEUqhFg/hqdefault.jpg)](https://www.youtube.com/watch?v=y_fmAEUqhFg) | [![Demonstration of Fire on a long matrix ](https://i.ytimg.com/vi/CgW5T-mRSvQ/hqdefault.jpg)](https://youtu.be/CgW5T-mRSvQ?t=43) | # PATTERNS ## Patterns from [Adafruit](https://www.adafruit.com/) @@ -99,13 +101,12 @@ NeoPatterns on breadboard ![NeoPatterns on breadboard](https://github.com/ArminJo/NeoPatterns/blob/master/extras/Breadboard_complete.jpg) # Revision History -### Version 2.3.2 - work in progress - -### Version 2.3.1 -- Removed restriction to 8 columns for `FireMatrix` pattern. +### Version 2.3.1 - work in progress +- Added `SnowMatrix` pattern. ### Version 2.3.0 - Changed TickerUpdate() and loadPicture() and their callers to achieve that YOffset is consistent with Y direction and origin. +- Removed restriction to 8 columns for `FireMatrix` pattern. ### Version 2.2.2 + 2.2.3 (2.2.2 was an incomplete version) - Fixed bugs if rows are not equal columns. diff --git a/examples/AllPatternsOnMultiDevices/ADCUtils.cpp b/examples/AllPatternsOnMultiDevices/ADCUtils.cpp index 2b96780..eef8c4e 100644 --- a/examples/AllPatternsOnMultiDevices/ADCUtils.cpp +++ b/examples/AllPatternsOnMultiDevices/ADCUtils.cpp @@ -22,8 +22,8 @@ * along with this program. If not, see . */ -#if defined(__AVR__) && (! defined(__AVR_ATmega4809__)) #include "ADCUtils.h" +#if defined(__AVR__) && defined(ADATE) // Union to speed up the combination of low and high bytes to a word // it is not optimal since the compiler still generates 2 unnecessary moves diff --git a/examples/AllPatternsOnMultiDevices/ADCUtils.h b/examples/AllPatternsOnMultiDevices/ADCUtils.h index 89073f5..f811616 100644 --- a/examples/AllPatternsOnMultiDevices/ADCUtils.h +++ b/examples/AllPatternsOnMultiDevices/ADCUtils.h @@ -26,6 +26,7 @@ #if defined(__AVR__) && (! defined(__AVR_ATmega4809__)) #include +#if defined(ADATE) // PRESCALE4 => 13 * 4 = 52 microseconds per ADC conversion at 1 MHz Clock => 19,2 kHz #define ADC_PRESCALE2 1 // 26 microseconds per ADC conversion at 1 MHz @@ -102,6 +103,9 @@ #define ADC_1_1_VOLT_CHANNEL_MUX 0x1E #define ADC_GND_CHANNEL_MUX 0x1F #define INTERNAL INTERNAL1V1 + +#else +#error "No temperature channel definitions specified for this AVR CPU" #endif uint16_t readADCChannel(uint8_t aChannelNumber); @@ -125,6 +129,7 @@ uint16_t getVCCVoltageMillivolt(void); void printVCCVoltageMillivolt(Print* aSerial); float getTemperature(void); +#endif // defined(ADATE) #endif // defined(__AVR__) #endif /* SRC_ADCUTILS_H_ */ diff --git a/examples/MatrixFire/MatrixFire.ino b/examples/MatrixFire/MatrixFire.ino index f3c9487..bec1620 100644 --- a/examples/MatrixFire/MatrixFire.ino +++ b/examples/MatrixFire/MatrixFire.ino @@ -73,13 +73,14 @@ void loop() { /* * Can set cooling and sparking parameters by potentiometers */ - // set cooling. 10 to 25 are sensible with optimum around 19 -// NeoPixelMatrix.PatternLength = map(analogRead(A0), 0, 1023, 5, 100); -// Serial.print(F("Cooling=")); -// Serial.print(NeoPixelMatrix.PatternLength); + // set cooling. 10 to 25 are sensible with optimum around 14 to 20 + NeoPixelMatrix.PatternLength = map(analogRead(A0), 0, 1023, 2, 40); + Serial.print(F("Cooling=")); + Serial.println(NeoPixelMatrix.PatternLength); -// NeoPixelMatrix.TotalStepCounter = map(analogRead(A1), 0, 1023, 30, 200); + // Not yet implemented +// NeoPixelMatrix.PatternFlags = map(analogRead(A1), 0, 1023, 30, 200); // Serial.print(F(" Sparking=")); -// Serial.println(NeoPixelMatrix.TotalStepCounter); +// Serial.println(NeoPixelMatrix.PatternFlags); } diff --git a/src/Colors.h b/src/Colors.h index 8ff8730..3f37b5e 100644 --- a/src/Colors.h +++ b/src/Colors.h @@ -84,6 +84,10 @@ typedef uint32_t color32_t; #define COLOR32_WHITE_HALF COLOR32(128,128,128) // to reduce power consumption #define COLOR32_WHITE_QUARTER COLOR32(64,64,64) // to reduce power consumption #define COLOR32_WHITE_EIGHTH COLOR32(32,32,32) // to reduce power consumption +#define COLOR32_WHITE_16TH COLOR32(16,16,16) +#define COLOR32_WHITE_32TH COLOR32(8,8,8) +#define COLOR32_WHITE_64TH COLOR32(4,4,4) +#define COLOR32_WHITE_32TH COLOR32(8,8,8) #define COLOR32_RED COLOR32(255,0,0) #define COLOR32_RED_HALF COLOR32(128,0,0) #define COLOR32_RED_QUARTER COLOR32(64,0,0) diff --git a/src/MatrixNeoPatterns.cpp b/src/MatrixNeoPatterns.cpp index 964063b..6574fc0 100644 --- a/src/MatrixNeoPatterns.cpp +++ b/src/MatrixNeoPatterns.cpp @@ -129,7 +129,9 @@ void MatrixNeoPatterns::setInitHeat() { #else tRandomValue.ULong = random(); #endif - initalHeatLine[tIndex] = (tRandomValue.UBytes[i] % (255-40)) + 40; + // Values from 40 to 255 + initalHeatLine[tIndex] = (tRandomValue.UBytes[i] - 40) + 40; // 40 is somewhat over represented +// initalHeatLine[tIndex] = ((tRandomValue.UBytes[i] * (255 - 40)) >> 8) + 40; // the correct one - just in case tIndex++; if (tIndex >= Columns) { return; @@ -145,6 +147,7 @@ void MatrixNeoPatterns::Fire(uint16_t aNumberOfSteps, uint16_t aIntervalMillis) Interval = aIntervalMillis; Direction = DIRECTION_UP; TotalStepCounter = aNumberOfSteps + 1; // + 1 step for the last pattern to show + PatternLength = MATRIX_FIRE_COOLING_PER_8_ROWS * 8 / Rows; // cooling affects the height of fire, the greater the value the smaller the fire Index = 3; // to call setInitHeat(); at startup // just to be sure @@ -240,8 +243,8 @@ bool MatrixNeoPatterns::FireMatrixUpdate() { uint8_t tNewHeatValue = MatrixOld[mapXYToArray(x, y, Columns + 2)] + (tConvolutionSumTimes256 / 256); // - COOLING and clipping to zero - if (tNewHeatValue > MATRIX_FIRE_COOLING) { - tNewHeatValue -= MATRIX_FIRE_COOLING; + if (tNewHeatValue > PatternLength) { + tNewHeatValue -= PatternLength; } else { tNewHeatValue = 0; } diff --git a/src/MatrixNeoPatterns.h b/src/MatrixNeoPatterns.h index 3a69a0b..d9dcf55 100644 --- a/src/MatrixNeoPatterns.h +++ b/src/MatrixNeoPatterns.h @@ -49,7 +49,7 @@ extern const uint8_t fontNumbers4x6[] PROGMEM; // the font for showing numbers #define NUMBERS_FONT_WIDTH 4 #define NUMBERS_FONT_HEIGHT 6 -#define MATRIX_FIRE_COOLING 20 // 10 to 25 are sensible with optimum around 19 +#define MATRIX_FIRE_COOLING_PER_8_ROWS 15 // for 8 rows 10 to 25 are sensible with optimum around 15 /* * The sum SHOULD be 0!!! * The Matrix which describes the contribution of each surrounding pixel to the next heat value. diff --git a/src/NeoPatterns.h b/src/NeoPatterns.h index a1ef994..c0614f4 100644 --- a/src/NeoPatterns.h +++ b/src/NeoPatterns.h @@ -283,9 +283,10 @@ void __attribute__((weak)) UserPattern2(NeoPatterns *aNeoPatterns, color32_t aCo /* * Version 2.3.1 - 12/2020 - * - Removed restriction to 8 columns for `FireMatrix` pattern. + * - Added `SnowMatrix` pattern. * * Version 2.3.0 - 12/2020 + * - Removed restriction to 8 columns for `FireMatrix` pattern. * - Changed TickerUpdate() and loadPicture() and their callers to achieve that YOffset is consistent with Y direction and origin. * * Version 2.2.2 /2.2.3- 12/2020