Created
August 11, 2021 21:43
-
-
Save nervusvagus/fbe83aed0f2fce1ffcaafc32c4a70ddb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CRGB base[NUM_LEDS]; | |
int8_t delta = 1; // 1 or -1. (Negative value reverses direction.) | |
#define RATE 20 //how fast patern moves (smaller number is faster) | |
//uint16_t StartPosition = 3; | |
//uint16_t pos = 0; // A pixel position. | |
void JellyFishBase() { | |
fill_solid( base, NUM_LEDS, CRGB::Red); // base color | |
base[0] = CRGB::Blue; | |
for (uint8_t j = 0; j < 2; j++) { | |
base[j] = CRGB::Blue; | |
} | |
for (uint8_t j = 2; j < 12; j++) { | |
base[j] = CRGB::Green; | |
} | |
for (uint8_t j = 12; j < 16; j++) { | |
base[j] = CHSV( 90, 255, 255); | |
} | |
for (uint8_t j = 16; j < 29; j++) { | |
base[j] = CRGB::Yellow; | |
} | |
for (uint8_t j = 29; j < 31; j++) { | |
base[j] = CHSV( 30, 255, 255); | |
} | |
for (uint8_t j = 31; j < 120; j++) { | |
base[j] = CRGB::Red; | |
} | |
for (uint8_t j = 120; j < 122; j++) { | |
base[j] = CRGB::Blue; | |
} | |
for (uint8_t j = 122; j < 134; j++) { | |
base[j] = CRGB::Green; | |
} | |
for (uint8_t j = 134; j < 137; j++) { | |
base[j] = CHSV( 90, 255, 255); | |
} | |
for (uint8_t j = 137; j < 148; j++) { | |
base[j] = CRGB::Yellow; | |
} | |
for (uint8_t j = 148; j < 152; j++) { | |
base[j] = CHSV( 30, 255, 255); | |
} | |
for (uint8_t j = 152; j < 230; j++) { | |
base[j] = CRGB::Red; | |
} | |
for (uint8_t j = 230; j < 232; j++) { | |
base[j] = CRGB::Blue; | |
} | |
for (uint8_t j = 232; j < 244; j++) { | |
base[j] = CRGB::Green; | |
} | |
for (uint8_t j = 244; j < 247; j++) { | |
base[j] = CHSV( 90, 255, 255); | |
} | |
for (uint16_t j = 247; j < 260; j++) { | |
base[j] = CRGB::Yellow; | |
} | |
for (uint16_t j = 260; j < 261; j++) { | |
base[j] = CHSV( 30, 255, 255); | |
} | |
JellyFishPattern(); | |
} | |
void JellyFishPattern() | |
{ | |
EVERY_N_MILLISECONDS(RATE) { | |
for (uint16_t i = 0; i < NUM_LEDS; i++) { | |
// leds[i+1] = base[i]; | |
leds[(pos + delta + i) % NUM_LEDS] = base[i]; | |
/// (pos + delta + i) % 255 ( uint8_t a, uint8_t m ) Calculate the remainder of one unsigned 8-bit value divided by anoter, aka A % M. Implemented by repeated subtraction, which is very compact, and very fast if A is 'probably' less than M. If A is a large multiple of M, the | |
// Serial.print("mod8(pos + delta + i, NUM_LEDS): "); Serial.print(mod8(pos + delta + i, NUM_LEDS)); Serial.print(" i "); Serial.print(i); Serial.print(" i+1 "); Serial.println(i+1); | |
} | |
// FastLED.show(); // Display the pixels. | |
pos = pos + delta; | |
if (pos == NUM_LEDS) { | |
pos = 0; //reset | |
} | |
// Serial.print("pos: "); Serial.println(pos); | |
} | |
} //end EVERY_N} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment