Skip to content

Commit

Permalink
Support not rotatebale palettes in runningPalette
Browse files Browse the repository at this point in the history
  • Loading branch information
CWempe committed Dec 5, 2018
1 parent 79574c5 commit 2d457ce
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 15 deletions.
5 changes: 4 additions & 1 deletion src/SuperLEDstrip.ino
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ void setTextAllSensors(void);
void Fire2012(void);
void arc_pulse(void);
void setupHalloween(void);
void staticPalette();
void showPalette (uint8_t colorIndex);
void halloween(void);
// void gradientFill(void);
void setScene(uint16_t scene);
void setPalette(uint8_t palette);
void setBrightness(uint8_t newBrightness);
Expand Down Expand Up @@ -89,6 +90,8 @@ bool halloweenFlickerState = false; // helper to save current state of flick
uint16_t halloweenFlashTimer = 1000; // initial flash timer value
bool halloweenFlashState = false; // helper to save current state of flashing; true = flashing on
bool paletteRotationable = true; // helper to define if a palette can be attatched to itselfe nicely
bool startPaletteInverted = false;
bool invert = false;

bool updateDisplayRed = false;
bool updateDisplayGreen = false;
Expand Down
24 changes: 19 additions & 5 deletions src/led_palette_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,29 @@ void setupStaticPalette() {
currentBlending = NOBLEND;
}


void staticPalette () {
uint8_t colorIndex = 0;
bool invert = false;
startPaletteInverted = false;
showPalette (0);
}


void showPalette (uint8_t colorIndex = 0) {
if ( !(colorIndex > 9 && colorIndex < 246)) {
Homie.getLogger() << "[DEBUG] showPalette " << colorIndex << " " << incIndex << " " << startPaletteInverted << " " << invert << endl;
}

// define all leds of the strip indivudually
for( uint16_t i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette( currentPalette, colorIndex, 255, currentBlending);
if ( startPaletteInverted == false ) {
leds[i] = ColorFromPalette( currentPalette, colorIndex, 255, currentBlending);
} else {
// invert colorIndex if the palette is started inverted
leds[i] = ColorFromPalette( currentPalette, 255 - colorIndex, 255, currentBlending);
}

// if palette cannot nicely attached to itselfe the palette will be printed in reverse
// think: "123456789987654321" instead of "123456789123456789"
// think: "123454321" instead of "1234512345"
if ( paletteRotationable == false ) {
if ( colorIndex >= ( 255 - incIndex) ) {
invert = true;
Expand All @@ -22,11 +36,11 @@ void staticPalette () {
if ( invert == false ) {
colorIndex += incIndex;
} else {
// decrease colorIndex if the palette is printed inverse
colorIndex -= incIndex;
}
} else {
colorIndex += incIndex;
}

}
}
6 changes: 1 addition & 5 deletions src/led_palettes.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ DEFINE_GRADIENT_PALETTE( purplefly_gp ) {
DEFINE_GRADIENT_PALETTE( thk_gp ) {
0, 255, 0, 0,
127, 255, 63, 0,
255, 255, 0,255};
255, 255, 0, 255};


CRGBPalette16 lala_p = CRGBPalette16(
Expand Down Expand Up @@ -164,10 +164,6 @@ void setPalette (uint8_t palette) {
case 102:
currentPalette = lala_p;
break;
case 103:
currentPalette = thk_gp;
paletteRotationable = true;
break;

// clubs
case 150:
Expand Down
22 changes: 18 additions & 4 deletions src/led_patterns.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,25 @@ void FillLEDsFromPaletteColors( uint8_t colorIndex)
void runningPalette()
{
static uint8_t startIndex = 0;
EVERY_N_MILLISECONDS(1000/NUM_LEDS)
{
startIndex = startIndex + 1;
invert = false;

// increase startIndex everytime this function is called
startIndex = startIndex + 1;

// define if the palette should be started inverted
// and change this behavier every time startIndex is 0
if ( paletteRotationable == false) {
if ( startIndex == 0 && startPaletteInverted == false) {
startPaletteInverted = true;
} else if ( startIndex == 0 && startPaletteInverted == true) {
startPaletteInverted = false;
}
} else {
startPaletteInverted = false;
}
FillLEDsFromPaletteColors( startIndex);

// generade led array based on the current startIndex
showPalette(startIndex);
}


Expand Down

0 comments on commit 2d457ce

Please sign in to comment.