Skip to content

Commit

Permalink
Housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
ArminJo committed Mar 19, 2024
1 parent f0a0a72 commit 7b1f999
Show file tree
Hide file tree
Showing 17 changed files with 153 additions and 65 deletions.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ If you are using PlatformIO, you can define the macros in the *[platformio.ini](
If you are using [Sloeber](https://eclipse.baeyens.it) as your IDE, you can easily define global symbols with *Properties > Arduino > CompileOptions*.<br/>
![Sloeber settings](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/pictures/SloeberDefineSymbols.png)

WOKWI online simulation of the AllPatternOnOneBar example.<br/>
[![WOKWI online simulation of the AllPatternOnOneBar example](https://github.com/ArminJo/NeoPatterns/blob/master/pictures/Wokwi_AllPatternOnOneBar.png)](https://wokwi.com/arduino/projects/299556508969992714).
[WOKWI online simulation of the AllPatternOnOneBar example](https://wokwi.com/arduino/projects/299556508969992714)
![Screenshot of WOKWI online simulation of the AllPatternOnOneBar example](https://github.com/ArminJo/NeoPatterns/blob/master/pictures/Wokwi_AllPatternOnOneBar.png)

WOKWI online simulation of the MatrixDemo example.<br/>
[![WOKWI online simulation of the MatrixDemo example](https://github.com/ArminJo/NeoPatterns/blob/master/pictures/Wokwi_MatrixDemo.png)](https://wokwi.com/arduino/projects/299560666027524617).
[WOKWI online simulation of the MatrixDemo example](https://wokwi.com/arduino/projects/299560666027524617)
![Screenshot of WOKWI online simulation of the MatrixDemo example](https://github.com/ArminJo/NeoPatterns/blob/master/pictures/Wokwi_MatrixDemo.png)

<br/>

Expand Down Expand Up @@ -217,8 +217,8 @@ AllPatternsOnMultiDevices on breadboard
Extended version of the OpenLedRace "version Basic for PCB Rome Edition. 2 Player, without Boxes Track".<br/>
See also the [dedicated repository for OpenLedRace](https://github.com/ArminJo/OpenledRace).

OpenLedRace at the Cologne public library MINTk�ln-Festival
![OpenLedRace at the Cologne public library MINTk�ln-Festival](https://github.com/ArminJo/OpenledRace/blob/master/pictures/OpenLedRaceAtMintFestival.jpg)
OpenLedRace at the Cologne public library MINTkoeln-Festival
![OpenLedRace at the Cologne public library MINTkoeln-Festival](https://github.com/ArminJo/OpenledRace/blob/master/pictures/OpenLedRaceAtMintFestival.jpg)

## TwoPatternsOnOneStrip
This example renders a slow "background pattern" and a fast "foreground pattern" on the same strip.<br/>
Expand All @@ -228,8 +228,7 @@ It also shows, how to dynamically **determine the length of the attached strip**

# Revision History
### Version 3.1.2 - work in progress
- Added function `getActualNeopixelLenghtSimple()`.
- Added function `clearAndShow()`.
- Added functions `getActualNeopixelLenghtSimple()`, `clearAndShow()`, `setMatrixPixelColorAndShow()` and `testMapping()`.

### Version 3.1.1
- Added parameter `aRepetitions` to pattern `RainbowCycle`.
Expand Down
13 changes: 8 additions & 5 deletions examples/MatrixPatternsTest/AVRUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ uint16_t getStackUnusedAndUsedBytes(uint16_t *aStackUsedBytesPointer) {
tHeapPtr++;
tStackUnused++;
}
*aStackUsedBytesPointer = (RAMEND - (uint16_t) tHeapPtr) + 1;
*aStackUsedBytesPointer = ((RAMEND + 1) - (uint16_t) tHeapPtr);

return tStackUnused;
}
Expand All @@ -95,8 +95,9 @@ uint16_t getStackUnusedAndUsedBytes(uint16_t *aStackUsedBytesPointer) {
* Returns the amount of stack/heap touched since the last call to initStackFreeMeasurement()
* by check for first non touched pattern on the stack/heap, starting the DOWNWARD search at current stack pointer.
*
* This returns too big value, if the end of former malloced and written memory was higher than current stackpointer,
* which nevertheless looks like a potential programming problem.
* If the end of former malloced and written memory was higher than current stackpointer,
* the memory area is taken as overwritten stack. Therefore we may return values, which are too big.
* But nevertheless, this constellation is likely a potential programming problem!
*/
uint16_t getStackUsedBytes() {
uint8_t tDummyVariableOnStack;
Expand All @@ -108,7 +109,7 @@ uint16_t getStackUsedBytes() {
tSearchPtr--;
}

return (RAMEND + 1) - (uint16_t)tSearchPtr;
return (RAMEND + 1) - (uint16_t) tSearchPtr;
}

/*
Expand Down Expand Up @@ -217,7 +218,9 @@ void printStackUnusedAndUsedBytesIfChanged(Print *aSerial) {
*/
void printRAMInfo(Print *aSerial) {
uint16_t tHeapStart = (uint16_t) getHeapStart();
aSerial->print(F("Size of Data + BSS, Heap start, Stack end="));
aSerial->print(F("Size of Data + BSS, Heap start, Stack end=0x"));
aSerial->print(tHeapStart - RAMSTART, HEX);
aSerial->print(F(" | "));
aSerial->println(tHeapStart - RAMSTART);

printStackUsedBytes(aSerial);
Expand Down
1 change: 1 addition & 0 deletions examples/MatrixPatternsTest/AVRUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <stdint.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include "avr/boot.h"

/*
* storage for millis value to enable compensation for interrupt disable at signal acquisition etc.
Expand Down
9 changes: 5 additions & 4 deletions examples/MatrixPatternsTest/EasyButtonAtInt01.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,15 @@ uint16_t EasyButton::updateButtonPressDuration() {
*/
uint8_t EasyButton::checkForLongPress(uint16_t aLongPressThresholdMillis) {
uint8_t tRetvale = EASY_BUTTON_LONG_PRESS_ABORT;
if (readDebouncedButtonState()) {
// noInterrupts() is required, since otherwise we may get wrong results if interrupted during processing by button ISR
noInterrupts();
if (readDebouncedButtonState() != BUTTON_IS_INACTIVE) {
// Button still active -> update current ButtonPressDurationMillis
// noInterrupts() is required, since otherwise we may get wrong results if interrupted during load of long value by button ISR
noInterrupts();

ButtonPressDurationMillis = millis() - ButtonLastChangeMillis;
interrupts();
tRetvale = EASY_BUTTON_LONG_PRESS_STILL_POSSIBLE; // if not detected, you may try again
}
interrupts();
if (ButtonPressDurationMillis >= aLongPressThresholdMillis) {
// long press detected
return EASY_BUTTON_LONG_PRESS_DETECTED;
Expand Down
13 changes: 8 additions & 5 deletions examples/MatrixSnow/AVRUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ uint16_t getStackUnusedAndUsedBytes(uint16_t *aStackUsedBytesPointer) {
tHeapPtr++;
tStackUnused++;
}
*aStackUsedBytesPointer = (RAMEND - (uint16_t) tHeapPtr) + 1;
*aStackUsedBytesPointer = ((RAMEND + 1) - (uint16_t) tHeapPtr);

return tStackUnused;
}
Expand All @@ -95,8 +95,9 @@ uint16_t getStackUnusedAndUsedBytes(uint16_t *aStackUsedBytesPointer) {
* Returns the amount of stack/heap touched since the last call to initStackFreeMeasurement()
* by check for first non touched pattern on the stack/heap, starting the DOWNWARD search at current stack pointer.
*
* This returns too big value, if the end of former malloced and written memory was higher than current stackpointer,
* which nevertheless looks like a potential programming problem.
* If the end of former malloced and written memory was higher than current stackpointer,
* the memory area is taken as overwritten stack. Therefore we may return values, which are too big.
* But nevertheless, this constellation is likely a potential programming problem!
*/
uint16_t getStackUsedBytes() {
uint8_t tDummyVariableOnStack;
Expand All @@ -108,7 +109,7 @@ uint16_t getStackUsedBytes() {
tSearchPtr--;
}

return (RAMEND + 1) - (uint16_t)tSearchPtr;
return (RAMEND + 1) - (uint16_t) tSearchPtr;
}

/*
Expand Down Expand Up @@ -217,7 +218,9 @@ void printStackUnusedAndUsedBytesIfChanged(Print *aSerial) {
*/
void printRAMInfo(Print *aSerial) {
uint16_t tHeapStart = (uint16_t) getHeapStart();
aSerial->print(F("Size of Data + BSS, Heap start, Stack end="));
aSerial->print(F("Size of Data + BSS, Heap start, Stack end=0x"));
aSerial->print(tHeapStart - RAMSTART, HEX);
aSerial->print(F(" | "));
aSerial->println(tHeapStart - RAMSTART);

printStackUsedBytes(aSerial);
Expand Down
1 change: 1 addition & 0 deletions examples/MatrixSnow/AVRUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <stdint.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include "avr/boot.h"

/*
* storage for millis value to enable compensation for interrupt disable at signal acquisition etc.
Expand Down
24 changes: 10 additions & 14 deletions examples/MatrixSnow/MatrixSnow.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MatrixSnow.cpp
*
* For testing the MatrixNeoPatterns Snow pattern
* For testing the MatrixNeoPatterns Snow pattern on a 16 x 16 or on a 8 x 8 matrix
*
* You need to install "Adafruit NeoPixel" library under "Tools -> Manage Libraries..." or "Ctrl+Shift+I" -> use "neoPixel" as filter string
*
Expand Down Expand Up @@ -32,36 +32,33 @@
//#define DO_NOT_SUPPORT_BRIGHTNESS // saves up to 428 bytes additional program memory for the AllPatternsOnMultiDevices() example.
//#define DO_NOT_SUPPORT_NO_ZERO_BRIGHTNESS // If activated, disables writing of zero only if brightness or color is zero. Saves up to 144 bytes ...

//#define DEBUG
#define INFO
#include <MatrixNeoPatterns.hpp>

#if defined(__AVR__)
#include "AVRUtils.h" // for printRAMInfo()
#endif

#define USE_16_X_16_MATRIX
#if defined(USE_16_X_16_MATRIX)
//#define USE_16_X_16_MATRIX // else 8x8 matrix

#define PIN_NEOPIXEL_MATRIX 8
#if defined(USE_16_X_16_MATRIX)
#define MATRIX_NUMBER_OF_COLUMNS 16
#define MATRIX_NUMBER_OF_ROWS 16
/*
* Specify your matrix geometry as 4th parameter.
* ....BOTTOM ....RIGHT specify the position of the zeroth pixel.
* See MatrixNeoPatterns.h for further explanation.
*/
MatrixNeoPatterns NeoPixelMatrix = MatrixNeoPatterns(MATRIX_NUMBER_OF_COLUMNS, MATRIX_NUMBER_OF_ROWS, PIN_NEOPIXEL_MATRIX,
NEO_MATRIX_BOTTOM | NEO_MATRIX_RIGHT | NEO_MATRIX_ROWS | NEO_MATRIX_ZIGZAG, NEO_GRB + NEO_KHZ800, NULL);
#define MATRIX_GEOMETRY (NEO_MATRIX_BOTTOM | NEO_MATRIX_RIGHT | NEO_MATRIX_ROWS | NEO_MATRIX_ZIGZAG)
#else
#define PIN_NEOPIXEL_MATRIX 8
#define MATRIX_NUMBER_OF_COLUMNS 8
#define MATRIX_NUMBER_OF_ROWS 8
#define MATRIX_GEOMETRY (NEO_MATRIX_BOTTOM | NEO_MATRIX_RIGHT | NEO_MATRIX_ROWS | NEO_MATRIX_PROGRESSIVE)
#endif
/*
* Specify your matrix geometry as 4th parameter.
* ....BOTTOM ....RIGHT specify the position of the zeroth pixel.
* See MatrixNeoPatterns.h for further explanation.
*/
MatrixNeoPatterns NeoPixelMatrix = MatrixNeoPatterns(MATRIX_NUMBER_OF_COLUMNS, MATRIX_NUMBER_OF_ROWS, PIN_NEOPIXEL_MATRIX,
NEO_MATRIX_BOTTOM | NEO_MATRIX_RIGHT | NEO_MATRIX_ROWS | NEO_MATRIX_PROGRESSIVE, NEO_GRB + NEO_KHZ800, NULL);
#endif
MATRIX_GEOMETRY, NEO_GRB + NEO_KHZ800, NULL);

void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Expand Down Expand Up @@ -95,7 +92,6 @@ void setup() {
}

void loop() {

NeoPixelMatrix.SnowUpdate();
NeoPixelMatrix.show();
NeoPixelMatrix.TotalStepCounter = 42; // set to any value > 1
Expand Down
13 changes: 8 additions & 5 deletions examples/OpenLedRace/AVRUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ uint16_t getStackUnusedAndUsedBytes(uint16_t *aStackUsedBytesPointer) {
tHeapPtr++;
tStackUnused++;
}
*aStackUsedBytesPointer = (RAMEND - (uint16_t) tHeapPtr) + 1;
*aStackUsedBytesPointer = ((RAMEND + 1) - (uint16_t) tHeapPtr);

return tStackUnused;
}
Expand All @@ -95,8 +95,9 @@ uint16_t getStackUnusedAndUsedBytes(uint16_t *aStackUsedBytesPointer) {
* Returns the amount of stack/heap touched since the last call to initStackFreeMeasurement()
* by check for first non touched pattern on the stack/heap, starting the DOWNWARD search at current stack pointer.
*
* This returns too big value, if the end of former malloced and written memory was higher than current stackpointer,
* which nevertheless looks like a potential programming problem.
* If the end of former malloced and written memory was higher than current stackpointer,
* the memory area is taken as overwritten stack. Therefore we may return values, which are too big.
* But nevertheless, this constellation is likely a potential programming problem!
*/
uint16_t getStackUsedBytes() {
uint8_t tDummyVariableOnStack;
Expand All @@ -108,7 +109,7 @@ uint16_t getStackUsedBytes() {
tSearchPtr--;
}

return (RAMEND + 1) - (uint16_t)tSearchPtr;
return (RAMEND + 1) - (uint16_t) tSearchPtr;
}

/*
Expand Down Expand Up @@ -217,7 +218,9 @@ void printStackUnusedAndUsedBytesIfChanged(Print *aSerial) {
*/
void printRAMInfo(Print *aSerial) {
uint16_t tHeapStart = (uint16_t) getHeapStart();
aSerial->print(F("Size of Data + BSS, Heap start, Stack end="));
aSerial->print(F("Size of Data + BSS, Heap start, Stack end=0x"));
aSerial->print(tHeapStart - RAMSTART, HEX);
aSerial->print(F(" | "));
aSerial->println(tHeapStart - RAMSTART);

printStackUsedBytes(aSerial);
Expand Down
1 change: 1 addition & 0 deletions examples/OpenLedRace/AVRUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <stdint.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include "avr/boot.h"

/*
* storage for millis value to enable compensation for interrupt disable at signal acquisition etc.
Expand Down
3 changes: 2 additions & 1 deletion examples/OpenLedRace/OpenLedRace.ino
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
//#include "AvrTracing.hpp"

#define VERSION_EXAMPLE "1.3"
// 1.3 VU Bar animations - work in progress
// 1.4 - work in progress
// 1.3 Moved Bridge and loop, VU Bar animations
// 1.2 Improvements from Hannover Maker Faire
// 1.1 Hannover Maker Faire version

Expand Down
6 changes: 3 additions & 3 deletions examples/OpenLedRace/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ Formula is: **NewSpeed = OldSpeed + Gravity + Friction + (OldSpeed * Drag)**
<br/>

# Pictures
| At the Hannover MakerFaire 2022 | At the Cologne public library MINTkln-Festival 2021 |
| At the Hannover MakerFaire 2022 | At the Cologne public library MINTk&ouml;ln-Festival 2021 |
| :-: | :-: |
| ![Accelerometer version from MakerFaire 2022](https://github.com/ArminJo/OpenledRace/blob/master/pictures/Overview.jpg) | ![OpenLedRace at the Cologne public library MINTkln-Festival](https://github.com/ArminJo/OpenledRace/blob/master/pictures/OpenLedRaceAtMintFestival.jpg) |
| ![Accelerometer version from MakerFaire 2022](https://github.com/ArminJo/OpenledRace/blob/master/pictures/Overview.jpg) | ![OpenLedRace at the Cologne public library MINTk&ouml;ln-Festival](https://github.com/ArminJo/OpenledRace/blob/master/pictures/OpenLedRaceAtMintFestival.jpg) |

<br/>

# YouTube Videos
| At the Hannover MakerFaire 2022 | At the Cologne public library MINTkln-Festival 2021 |
| At the Hannover MakerFaire 2022 | At the Cologne public library MINTk&ouml;ln-Festival 2021 |
| :-: | :-: |
| [![OpenLedRace at the Hannover MakerFaire 2022](https://i.ytimg.com/vi/lYzYpFYJfWI/hqdefault.jpg)](https://www.youtube.com/watch?v=lYzYpFYJfWI) | [![OpenLedRace in action](https://i.ytimg.com/vi/y25rjRkDg0g/hqdefault.jpg)](https://www.youtube.com/watch?v=y25rjRkDg0g) |

Expand Down
4 changes: 4 additions & 0 deletions examples/OpenLedRace/SoftI2CMaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,11 @@ bool i2c_init(void)
TWSR = (1<<TWPS0); // prescaler is 4
TWBR = ((I2C_CPUFREQ/SCL_CLOCK)-16)/8;
#endif
#if defined(digitalReadFast)
return (digitalReadFast(SDA) != 0 && digitalReadFast(SCL) != 0);
#else
return (digitalRead(SDA) != 0 && digitalRead(SCL) != 0);
#endif
}
#else // I2C_HARDWARE
{
Expand Down
9 changes: 5 additions & 4 deletions examples/TwoPatternsOnOneStrip/EasyButtonAtInt01.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,15 @@ uint16_t EasyButton::updateButtonPressDuration() {
*/
uint8_t EasyButton::checkForLongPress(uint16_t aLongPressThresholdMillis) {
uint8_t tRetvale = EASY_BUTTON_LONG_PRESS_ABORT;
if (readDebouncedButtonState()) {
// noInterrupts() is required, since otherwise we may get wrong results if interrupted during processing by button ISR
noInterrupts();
if (readDebouncedButtonState() != BUTTON_IS_INACTIVE) {
// Button still active -> update current ButtonPressDurationMillis
// noInterrupts() is required, since otherwise we may get wrong results if interrupted during load of long value by button ISR
noInterrupts();

ButtonPressDurationMillis = millis() - ButtonLastChangeMillis;
interrupts();
tRetvale = EASY_BUTTON_LONG_PRESS_STILL_POSSIBLE; // if not detected, you may try again
}
interrupts();
if (ButtonPressDurationMillis >= aLongPressThresholdMillis) {
// long press detected
return EASY_BUTTON_LONG_PRESS_DETECTED;
Expand Down
11 changes: 10 additions & 1 deletion src/ADCUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,33 @@
#define ADC_TEMPERATURE_CHANNEL_MUX 15
#define ADC_1_1_VOLT_CHANNEL_MUX 12
#define ADC_GND_CHANNEL_MUX 13
#define ADC_CHANNEL_MUX_MASK 0x0F

#elif defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)
#define ADC_ISCR_CHANNEL_MUX 3
#define ADC_TEMPERATURE_CHANNEL_MUX 11
#define ADC_1_1_VOLT_CHANNEL_MUX 12
#define ADC_GND_CHANNEL_MUX 14
#define ADC_VCC_4TH_CHANNEL_MUX 13
#define ADC_CHANNEL_MUX_MASK 0x1F

#elif defined(__AVR_ATmega328P__)
#define ADC_TEMPERATURE_CHANNEL_MUX 8
#define ADC_1_1_VOLT_CHANNEL_MUX 14
#define ADC_GND_CHANNEL_MUX 15
#define ADC_CHANNEL_MUX_MASK 0x0F

#elif defined(__AVR_ATmega32U4__)
#define ADC_TEMPERATURE_CHANNEL_MUX 0x27
#define ADC_1_1_VOLT_CHANNEL_MUX 0x1E
#define ADC_GND_CHANNEL_MUX 0x1F
#define ADC_CHANNEL_MUX_MASK 0x3F

#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__)
#define ADC_1_1_VOLT_CHANNEL_MUX 0x1E
#define ADC_GND_CHANNEL_MUX 0x1F
#define ADC_CHANNEL_MUX_MASK 0x1F

#define INTERNAL INTERNAL1V1

#else
Expand Down Expand Up @@ -164,7 +170,10 @@ uint16_t waitAndReadADCChannelWithReferenceAndRestoreADMUXAndReference(uint8_t a
uint16_t readADCChannelWithOversample(uint8_t aADCChannelNumber, uint8_t aOversampleExponent);
void setADCChannelAndReferenceForNextConversion(uint8_t aADCChannelNumber, uint8_t aReference);
uint16_t readADCChannelWithReferenceOversampleFast(uint8_t aADCChannelNumber, uint8_t aReference, uint8_t aOversampleExponent);
uint16_t readADCChannelWithReferenceMultiSamples(uint8_t aADCChannelNumber, uint8_t aReference, uint8_t aNumberOfSamples);
uint32_t readADCChannelMultiSamples(uint8_t aPrescale, uint16_t aNumberOfSamples);
uint16_t readADCChannelMultiSamplesWithReference(uint8_t aADCChannelNumber, uint8_t aReference, uint8_t aNumberOfSamples);
uint32_t readADCChannelMultiSamplesWithReferenceAndPrescaler(uint8_t aADCChannelNumber, uint8_t aReference, uint8_t aPrescale,
uint16_t aNumberOfSamples);
uint16_t readADCChannelWithReferenceMax(uint8_t aADCChannelNumber, uint8_t aReference, uint16_t aNumberOfSamples);
uint16_t readADCChannelWithReferenceMaxMicros(uint8_t aADCChannelNumber, uint8_t aReference, uint16_t aMicrosecondsToAquire);
uint16_t readUntil4ConsecutiveValuesAreEqual(uint8_t aADCChannelNumber, uint8_t aReference, uint8_t aDelay,
Expand Down
Loading

0 comments on commit 7b1f999

Please sign in to comment.