Skip to content

Commit

Permalink
Version 2.2.0 RGBW support
Browse files Browse the repository at this point in the history
  • Loading branch information
ArminJo committed Apr 13, 2020
1 parent 96808c5 commit 7ebc632
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 49 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/LibraryBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ jobs:
runs-on: ubuntu-latest # I picked Ubuntu to use shell scripts.

env:
# Space separated list without double quotes around the list.
# If you need a library with a space in its name, like Adafruit NeoPixel or Adafruit INA219, you must use double quotes
# around the name and have at least 2 entries, where the first must be without double quotes! You may use Servo as dummy entry.
REQUIRED_LIBRARIES: Servo "Adafruit NeoPixel"
# Comma separated list without double quotes around the list.
REQUIRED_LIBRARIES: Adafruit NeoPixel

strategy:
matrix:
Expand All @@ -35,6 +33,7 @@ jobs:
#############################################################################################################
arduino-boards-fqbn:
- arduino:avr:uno
- arduino:avr:uno|All-DO_NOT_SUPPORT_RGBW
- arduino:avr:leonardo
- arduino:avr:mega
- esp8266:esp8266:huzzah:eesz=4M3M,xtal=80
Expand All @@ -44,13 +43,18 @@ jobs:
# Parameters can be: examples-exclude and examples-build-properties
#############################################################################################################
include:
- arduino-boards-fqbn: arduino:avr:uno|All-DO_NOT_SUPPORT_RGBW
examples-build-properties:
All:
-DDO_NOT_SUPPORT_RGBW

- arduino-boards-fqbn: esp8266:esp8266:huzzah:eesz=4M3M,xtal=80
platform-url: https://arduino.esp8266.com/stable/package_esp8266com_index.json
examples-exclude: OpenLedRace TwoPatternsOnOneStrip # Space separated list of (unique substrings of) example names to exclude in build
examples-exclude: OpenLedRace,TwoPatternsOnOneStrip # Comma separated list of (unique substrings of) example names to exclude in build

- arduino-boards-fqbn: esp32:esp32:featheresp32:FlashFreq=80
platform-url: https://dl.espressif.com/dl/package_esp32_index.json
examples-exclude: OpenLedRace TwoPatternsOnOneStrip # TwoPatternsOnOneStrip because of missing EasyButton library
examples-exclude: OpenLedRace,TwoPatternsOnOneStrip # TwoPatternsOnOneStrip because of missing EasyButton library

# Do not cancel all jobs / architectures if one job fails
fail-fast: false
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ Examples:
**All matrix pixel mappings except NEO_MATRIX_COLUMNS are supported**
In case you need `NEO_MATRIX_COLUMNS` layout, try to rotate your Matrix and use `NEO_MATRIX_ROWS` or use your own custom mapping function.

## Reducing library size
If you do not have RGBW pixels, then you can save program space by commenting out the line `#define SUPPORT_RGBW` in *NeoPixel.h* or defining `DO_NOT_SUPPORT_RGBW` as global symbol. This saves e.g 400 bytes FLASH for the AllPatternsOnMultiDevices example.

### Modifying library properties
To access the Arduino library files from a sketch, you have to first use *Sketch/Show Sketch Folder (Ctrl+K)* in the Arduino IDE.<br/>
Then navigate to the parallel `libraries` folder and select the library you want to access.<br/>
The library files itself are located in the `src` sub-directory.<br/>
If you did not yet store the example as your own sketch, then with *Ctrl+K* you are instantly in the right library folder.

# SNAKE GAME
## SnakeGame Example
The game can be controlled by 2 or 4 buttons or by serial input (WASD). To enable serial input control you must comment out the line `#define USE_SERIAL_CONTROL` in the library file *MatrixSnake.h* or define global symbol with `-DUSE_SERIAL_CONTROL` which is not yet possible in Arduino IDE:-(.<br/>
Expand All @@ -76,6 +85,7 @@ NeoPatterns on breadboard

# Revision History
### Version 2.2.0
- Added support for RGBW patterns. Requires additional 200 bytes for the AllPatternsOnMultiDevices example. Commenting out `#define SUPPORT_RGBW` or defining `DO_NOT_SUPPORT_RGBW` saves 400 bytes FLASH for the AllPatternsOnMultiDevices example.
- Use type `Print *` instead of `Stream *`.
- Changed function `addPixelColor()`.
- Added function `NeoPixel::printInfo(aSerial)`.
Expand Down
9 changes: 8 additions & 1 deletion examples/OpenLedRace/AVRUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,17 @@ bool isAddressBelowHeap(void * aAddressToCheck) {
********************************************/
volatile uint16_t sNumberOfSleeps = 0;

#ifndef MILLIS_UTILS_H_
// copied from MillisUtils.h
/*
* storage for millis value to enable millis() compensation for sleep.
* storage for millis value to enable compensation for interrupt disable at signal acquisition etc.
*/
#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)
#define timer0_millis millis_timer_millis // The ATTinyCore libraries use other variable name in wiring.c
#endif

extern volatile unsigned long timer0_millis;
#endif // MILLIS_UTILS_H_

void initSleep(uint8_t tSleepMode) {
sleep_enable()
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=NeoPatterns
version=2.1.0
version=2.2.0
author=Armin Joachimsmeyer
maintainer=Armin Joachimsmeyer <[email protected]>
sentence=Patterns for NeoPixel strips and matrixes including the patterns of the NeoPattern Example by Adafruit.<br/>
Expand Down
6 changes: 4 additions & 2 deletions src/Colors.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <stdint.h>

// deprecated
typedef uint16_t Color_t;
typedef uint16_t Color_t __attribute__ ((deprecated ("Renamed to color16_t")));;
// new
typedef uint16_t color16_t;

Expand Down Expand Up @@ -69,9 +69,11 @@ typedef uint16_t color16_t;
*/
typedef uint32_t color32_t;

// Eases constant color declarations but should not be used for non constant colors. Then better use Adafruit_NeoPixel::Color() it saves program space
// Eases constant color declarations but should only be used for constant colors. Otherwise better use Adafruit_NeoPixel::Color() it saves program space
#define COLOR32(r,g,b) ((color32_t)(((uint32_t)r<<16)|((uint16_t)g<<8)|b)) // return ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
#define COLOR_W32(r,g,b,w) ((color32_t)(((uint32_t)w<<24)|((uint32_t)r<<16)|((uint16_t)g<<8)|b)) // return ((uint32_t)w << 24) |(uint32_t)r << 16) | ((uint32_t)g << 8) | b;

#define WHITE(color) ((color >> 24) & 0xFF)
#define RED(color) ((color >> 16) & 0xFF)
#define GREEN(color) ((color >> 8) & 0xFF)
#define BLUE(color) (color 0xFF)
Expand Down
76 changes: 48 additions & 28 deletions src/NeoPatterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,15 @@ bool NeoPatterns::FadeUpdate(bool aDoUpdate) {
*/
// Calculate linear interpolation between Color1 and BackgroundColor
// Optimize order of operations to minimize truncation error
uint8_t red = ((Red(Color1) * (PatternLength - Index)) + (Red(LongValue1.Color2) * Index)) / PatternLength;
uint8_t green = ((Green(Color1) * (PatternLength - Index)) + (Green(LongValue1.Color2) * Index)) / PatternLength;
uint8_t blue = ((Blue(Color1) * (PatternLength - Index)) + (Blue(LongValue1.Color2) * Index)) / PatternLength;
ColorSet(Color(red, green, blue));
uint8_t tRed = ((Red(Color1) * (PatternLength - Index)) + (Red(LongValue1.Color2) * Index)) / PatternLength;
uint8_t tGreen = ((Green(Color1) * (PatternLength - Index)) + (Green(LongValue1.Color2) * Index)) / PatternLength;
uint8_t tBlue = ((Blue(Color1) * (PatternLength - Index)) + (Blue(LongValue1.Color2) * Index)) / PatternLength;
#ifdef SUPPORT_RGBW
uint8_t tWhite = ((White(Color1) * (PatternLength - Index)) + (White(LongValue1.Color2) * Index)) / PatternLength;
ColorSet(Color(tRed, tGreen, tBlue, tWhite));
#else
ColorSet(Color(tRed, tGreen, tBlue));
#endif
}
return false;
}
Expand Down Expand Up @@ -1317,42 +1322,57 @@ bool NeoPatterns::ProcessSelectiveColorUpdate(bool aDoUpdate) {
/***********************************************************
* Sample processing functions for ProcessSelectiveColor()
***********************************************************/
color32_t FadeColor(NeoPatterns * aLedPtr) {
aLedPtr->Index++;
uint16_t tIndex = aLedPtr->Index;
uint16_t tTotalSteps = aLedPtr->TotalStepCounter;
color32_t tColor1 = aLedPtr->Color1;
color32_t tColor2 = aLedPtr->LongValue1.Color2;
uint8_t red = ((Red(tColor1) * (tTotalSteps - tIndex)) + (Red(tColor2) * tIndex)) / tTotalSteps;
uint8_t green = ((Green(tColor1) * (tTotalSteps - tIndex)) + (Green(tColor2) * tIndex)) / tTotalSteps;
uint8_t blue = ((Blue(tColor1) * (tTotalSteps - tIndex)) + (Blue(tColor2) * tIndex)) / tTotalSteps;
return Adafruit_NeoPixel::Color(red, green, blue);
color32_t FadeColor(NeoPatterns * aNeoPatternsPtr) {
aNeoPatternsPtr->Index++;
uint16_t tIndex = aNeoPatternsPtr->Index;
uint16_t tTotalSteps = aNeoPatternsPtr->TotalStepCounter;
color32_t tColor1 = aNeoPatternsPtr->Color1;
color32_t tColor2 = aNeoPatternsPtr->LongValue1.Color2;
uint8_t tRed = ((Red(tColor1) * (tTotalSteps - tIndex)) + (Red(tColor2) * tIndex)) / tTotalSteps;
uint8_t tGreen = ((Green(tColor1) * (tTotalSteps - tIndex)) + (Green(tColor2) * tIndex)) / tTotalSteps;
uint8_t tBlue = ((Blue(tColor1) * (tTotalSteps - tIndex)) + (Blue(tColor2) * tIndex)) / tTotalSteps;
#ifdef SUPPORT_RGBW
uint8_t tWhite = ((White(tColor1) * (tTotalSteps - tIndex)) + (White(tColor2) * tIndex)) / tTotalSteps;
return Adafruit_NeoPixel::Color(tRed, tGreen, tBlue, tWhite);
#else
return Adafruit_NeoPixel::Color(tRed, tGreen, tBlue);
#endif
}

/*
* works on LongValue2.ColorTmp
*/
color32_t DimColor(NeoPatterns * aLedPtr) {
color32_t tColor = aLedPtr->LongValue2.ColorTmp;
uint8_t red = Red(tColor) >> 1;
uint8_t green = Green(tColor) >> 1;
uint8_t blue = Blue(tColor) >> 1;
// call to function saves 6 byte program space
return Adafruit_NeoPixel::Color(red, green, blue);
color32_t DimColor(NeoPatterns * aNeoPatternsPtr) {
color32_t tColor = aNeoPatternsPtr->LongValue2.ColorTmp;
uint8_t tRed = Red(tColor) >> 1;
uint8_t tGreen = Green(tColor) >> 1;
uint8_t tBlue = Blue(tColor) >> 1;
#ifdef SUPPORT_RGBW
uint8_t tWhite = White(tColor) >> 1;
return Adafruit_NeoPixel::Color(tRed, tGreen, tBlue, tWhite);
#else
// call to function saves 6 byte program space
return Adafruit_NeoPixel::Color(tRed, tGreen, tBlue);
#endif

// return COLOR32(red, green, blue);
}

/*
* works on LongValue2.ColorTmp
*/
color32_t BrightenColor(NeoPatterns * aLedPtr) {
color32_t tColor = aLedPtr->LongValue2.ColorTmp;
uint8_t red = Red(tColor) << 1;
uint8_t green = Green(tColor) << 1;
uint8_t blue = Blue(tColor) << 1;
color32_t BrightenColor(NeoPatterns * aNeoPatternsPtr) {
color32_t tColor = aNeoPatternsPtr->LongValue2.ColorTmp;
uint8_t tRed = Red(tColor) << 1;
uint8_t tGreen = Green(tColor) << 1;
uint8_t tBlue = Blue(tColor) << 1;
#ifdef SUPPORT_RGBW
uint8_t tWhite = White(tColor) << 1;
return Adafruit_NeoPixel::Color(tRed, tGreen, tBlue, tWhite);
#else
// call to function saves 22 byte program space
return Adafruit_NeoPixel::Color(red, green, blue);
// return COLOR32(red, green, blue);
return Adafruit_NeoPixel::Color(tRed, tGreen, tBlue);// return COLOR32(red, green, blue);
#endif
}

#if defined(__AVR__)
Expand Down
10 changes: 6 additions & 4 deletions src/NeoPatterns.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
#define VERSION_NEOPATTERNS_NUMERICAL 220

/*
* Version 2.2.0 - 1/2020
* Version 2.2.0 - 4/2020
* - Added support for RGBW patterns. Requires additional 200 bytes for AllPatternsOnMultiDevices example.
* Not defining SUPPORT_RGBW saves 400 bytes FLASH for AllPatternsOnMultiDevices example.
* - Use type `Print *` instead of `Stream *`.
* - Changed function `addPixelColor()`.
* - Added function `NeoPixel::printInfo(aSerial)`.
Expand Down Expand Up @@ -286,9 +288,9 @@ class NeoPatterns: public virtual NeoPixel {
};

// Sample processing functions for ProcessSelectiveColor()
color32_t FadeColor(NeoPatterns* aLedPtr);
color32_t DimColor(NeoPatterns* aLedPtr);
color32_t BrightenColor(NeoPatterns* aLedPtr);
color32_t FadeColor(NeoPatterns* aNeoPatternsPtr);
color32_t DimColor(NeoPatterns* aNeoPatternsPtr);
color32_t BrightenColor(NeoPatterns* aNeoPatternsPtr);

// multiple pattern example
void initMultipleFallingStars(NeoPatterns * aLedsPtr, color32_t aColor, uint8_t aLength, uint8_t aDuration, uint8_t aRepetitions,
Expand Down
Loading

0 comments on commit 7ebc632

Please sign in to comment.