<commit_before>#define qsubd(x, b)  ((x>b)?wavebright:0)                     // Digital unsigned subtraction macro. if result <0, then => 0. Otherwise, take on fixed value.
#define qsuba(x, b)  ((x>b)?x-b:0)                            // Analog Unsigned subtraction macro. if result <0, then => 0

#include "FastLED.h"
#define LED_DT 7                                             // Data pin to connect to the strip.
#define COLOR_ORDER GRB                                       // Are they RGB, GRB or what??
#define LED_TYPE WS2812B                                       // Don't forget to change LEDS.addLeds
#define NUM_LEDS 1500                                           // Number of LED's.
struct CRGB leds[NUM_LEDS];                                   // Initialize our LED array.

uint8_t max_bright = 255;                                      // Overall brightness definition. It can be changed on the fly.
unsigned long previousMillis;                                 // Store last time the strip was updated.

uint8_t   thisfade = 200;                                      // How quickly does it fade? Lower = slower fade rate.
int        thishue = 50;                                       // Starting hue.
uint8_t    thisinc = 1;                                        // Incremental value for rotating hues
uint8_t    thissat = 240;                                      // The saturation, where 255 = brilliant colours.
uint8_t    thisbri = 255;                                      // Brightness of a sequence. Remember, max_bright is the overall limiter.
int        huediff = 256;                                      // Range of random #'s to use for hue
uint8_t  thisdelay = 0;                                        // We don't need much delay (if any)

uint8_t    numdots = 4;                                     // Number of dots in use.
uint8_t   faderate = 128;                                     // How long should the trails be. Very low value = longer trails.
uint8_t     hueinc = 16;                                     // Incremental change in hue between each dot.
uint8_t     curhue = 0;                                     // The current hue
uint8_t thisbright = 255;                                     // How bright should the LED/display be.
uint8_t   basebeat = 48;                                     // Higher = faster movement.

uint8_t wavebright = 255;                                     // You can change the brightness of the waves/bars rolling across the screen.
uint8_t    thisrot = 1;                                          // You can change how quickly the hue rotates for this wave. Currently 0.
uint8_t     allsat = 240;                                         // I like 'em fully saturated with colour.
int8_t   thisspeed = 48;                                         // You can change the speed of the wave, and use negative values.
uint8_t    allfreq = 3;                                         // You can change the frequency, thus distance between bars.
int      thisphase = 0;                                            // Phase change value gets calculated.
uint8_t thiscutoff = 120;                                     // You can change the cutoff value to display this wave. Lower value = longer wave.
uint8_t      bgclr = 0;                                            // A rotating background colour.
uint8_t      bgbri = 0;


#define RAINBOW 1
#define RAINBOW_2 2
#define RAINBOW_3 2
#define DISCO_BARBER_1 3
#define DISCO_BARBER_2 4
#define JUGGLE 5
#define NEW 6

int maxPatternId = 5;
int patternId = random(maxPatternId - 1);
bool holdPattern = false;
int rotationInMillseconds = 20000;

const int ledPin = 13;
const int led = 13;

void setup() {
  delay(3000);
  Serial.begin(57600);
  LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);
  FastLED.setBrightness(max_bright);
  set_max_power_in_volts_and_milliamps(5, 10000);
}

int numberOfSparkles = 1;
int increasing = true;

void confetti() {
  fadeToBlackBy(leds, NUM_LEDS, thisfade);
  if (numberOfSparkles < 40 && increasing) {
    numberOfSparkles += 1;
  } else if (numberOfSparkles > 5) {
    numberOfSparkles -= 1;
    increasing = false;
  } else {
    increasing = true;
    numberOfSparkles += 1;
  }

  int pos;

  if (patternId == RAINBOW) {
    for (int i = 0; i < 2; i++) {
      pos = random16(NUM_LEDS);
      leds[pos] += CHSV(thishue, 255, 255);
    }
  }

  for (int i = 0; i < numberOfSparkles * 8; i++) {
    pos = random16(NUM_LEDS);
    if (patternId == RAINBOW) {
      leds[pos] += CHSV(thishue, 255, 20);
    } else if (patternId == RAINBOW_2) {
      leds[pos] = CHSV(thishue + (pos / 10), thissat, thisbri);
    } else if (patternId == RAINBOW_3) {
      leds[pos] = CHSV(thishue, thissat, thisbri);
    }
  }

  if (patternId == RAINBOW_2) {
    thishue += thisinc * 10;
  }

  thishue = thishue + thisinc;
}

void juggle() {
  fadeToBlackBy(leds, NUM_LEDS, faderate);
  numdots = 3; basebeat = 2; hueinc = 1; faderate = 48; thishue = 128;
  for ( int i = 0; i < numdots; i++) {
    for ( int j = 0; j < 20; j++) {
      leds[beatsin16(basebeat + i + numdots, 0, NUM_LEDS - 20) + j] += CHSV(curhue, thissat, thisbright); //beat16 is a FastLED 3.1 function
    }
//    leds[beatsin16(basebeat + i + numdots, 0, NUM_LEDS)] += CHSV(curhue, thissat, thisbright); //beat16 is a FastLED 3.1 function
    curhue += hueinc;
  }
}

void discoBarber() {
  thisphase += thisspeed;                                                     // You can change direction and speed individually.
  thishue = thishue + thisrot;                                                // Hue rotation is fun for thiswave.
  for (int k = 0; k < NUM_LEDS - 1; k++) {                                    // For each of the LED's in the strand, set a brightness based on a wave as follows:
    int thisbright = qsubd(cubicwave8((k * allfreq) + thisphase), thiscutoff); // qsub sets a minimum value called thiscutoff. If < thiscutoff, then bright = 0. Otherwise, bright = 128 (as defined in qsub)..
    leds[k] = CHSV(bgclr, 255, bgbri);                                        // First set a background colour, but fully saturated.

    // Sparkles!
    if (random(1000) > 997) {
      leds[k] = CHSV(255, 0, 255);
    }

    if (patternId == DISCO_BARBER_1) {
      leds[k] += CHSV(thishue+k/5, allsat, thisbright);                             // Then assign a hue to any that are bright enough.
    } else {
      leds[k] += CHSV(- (thishue * 20) + k / 4, allsat, thisbright);                       // Then assign a hue to any that are bright enough.
    }
  }
  bgclr++;
}

void loop () {
  if (!holdPattern) {
    EVERY_N_MILLISECONDS(rotationInMillseconds) {
      patternId += 1;
      if (patternId > maxPatternId) {
        patternId = 1;
      }
    }
  }

  if (patternId == RAINBOW || patternId == RAINBOW_2 || patternId == RAINBOW_3) {
    confetti();
  } else if (patternId == DISCO_BARBER_1 || patternId == DISCO_BARBER_2) {
    discoBarber();
  } else if (patternId == JUGGLE) {
    juggle();
  }
  show_at_max_brightness_for_power();
}<commit_msg>Nice patterns here. Going to rewrite each into its own function now<commit_after>uint8_t wavebright = 255;                                     // You can change the brightness of the waves/bars rolling across the screen.
#define qsubd(x, b)  ((x>b)?wavebright:0)                     // Digital unsigned subtraction macro. if result <0, then => 0. Otherwise, take on fixed value.
#define qsuba(x, b)  ((x>b)?x-b:0)                            // Analog Unsigned subtraction macro. if result <0, then => 0

#include "FastLED.h"
#define LED_DT 7                                             // Data pin to connect to the strip.
#define COLOR_ORDER GRB                                       // Are they RGB, GRB or what??
#define LED_TYPE WS2812B                                       // Don't forget to change LEDS.addLeds
#define NUM_LEDS 1500                                           // Number of LED's.
struct CRGB leds[NUM_LEDS];                                   // Initialize our LED array.

uint8_t max_bright = 255;                                      // Overall brightness definition. It can be changed on the fly.
unsigned long previousMillis;                                 // Store last time the strip was updated.

int hue = 50;                                       // Starting hue.

// This variable is set the first run-through of every pattern. Use it for setup!
bool firstRun = false;

// Patterns
#define RAINBOW 1
#define RAINBOW_2 2
#define RAINBOW_3 3
#define DISCO_BARBER_1 4
#define DISCO_BARBER_2 5
#define JUGGLE 6
#define NEW 7

int maxPatternId = 6;
int rotationInMillseconds = 20000; // 20 seconds for production


//int patternId = 3;
//bool holdPattern = false;
bool holdPattern = true;
int patternId = RAINBOW;

const int ledPin = 13;
const int led = 13;

void setup() {
  delay(3000);
  Serial.begin(57600);
  LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);
  FastLED.setBrightness(max_bright);
  set_max_power_in_volts_and_milliamps(5, 10000);
  randomSeed(analogRead(0));
}

int numberOfSparkles = 1;
int increasing = true;

void confetti() {

  if (patternId == RAINBOW) {
    fadeToBlackBy(leds, NUM_LEDS, 180);
  } else {
    fadeToBlackBy(leds, NUM_LEDS, 200);
  }
  
  if (numberOfSparkles < 80 && increasing) {
    numberOfSparkles += 1;
  } else if (numberOfSparkles > 5) {
    numberOfSparkles -= 1;
    increasing = false;
  } else {
    increasing = true;
    numberOfSparkles += 1;
  }

  int pos;

  if (patternId == RAINBOW) {
    for (int i = 0; i < 20; i++) {
      pos = random16(NUM_LEDS);
      leds[pos] = CHSV(hue, 180, 255);
    }
  }

  for (int i = 0; i < numberOfSparkles * 4; i++) {
    pos = random16(NUM_LEDS);
    if (patternId == RAINBOW) {
      leds[pos] += CHSV(hue, 200, 20);
    } else if (patternId == RAINBOW_2) {
      leds[pos] = CHSV(hue + (pos / 10), 240, 255);
    } else if (patternId == RAINBOW_3) {
      leds[pos] = CHSV(hue, 240, 255);
    }
  }

  if (patternId == RAINBOW_2) {
    hue += 10;
  } else {
    hue = hue + 1;
  }
}

uint8_t    numdots = 3;    // Number of dots in use.
uint8_t   faderate = 64;  // How long should the trails be. Very low value = longer trails.
uint8_t     hueinc = 1;   // Incremental change in hue between each dot.
uint8_t     curhue = 0;    // The current hue
uint8_t   basebeat = 2;   // Higher = faster movement.

void juggle() {
  hueinc = 1;
  faderate = 64;
  if (faderate == 100 || faderate == 200) {
    numdots += 1;
  }
  
  fadeToBlackBy(leds, NUM_LEDS, faderate);
  
  for ( int i = 0; i < numdots; i++) {
    for ( int j = 0; j < 20; j++) {
      leds[beatsin16(basebeat + i + numdots, 0, NUM_LEDS - 20) + j] += CHSV(curhue, 240, 255); //beat16 is a FastLED 3.1 function
    }
    // leds[beatsin16(basebeat + i + numdots, 0, NUM_LEDS)] += CHSV(curhue, 240, 255); //beat16 is a FastLED 3.1 function
    curhue += hueinc;
  }
}

uint8_t allfreq = 3;
int     thisphase = 0;
uint8_t thiscutoff = 120;
uint8_t thisrot = 1;
int8_t  thisspeed = 48;
uint8_t allsat = 240;

void discoBarber() {
  if (patternId == DISCO_BARBER_1) {
    allfreq = 5;
    thisphase += 24;
  } else {
    allfreq = 3;
    thisphase += 48;
  }
  
  hue = hue + 1;                                                // Hue rotation is fun for thiswave.

  for (int k = 0; k < NUM_LEDS - 1; k++) {                                    // For each of the LED's in the strand, set a brightness based on a wave as follows:
    int _brightness = qsubd(cubicwave8((k * allfreq) + thisphase), thiscutoff); // qsub sets a minimum value called thiscutoff. If < thiscutoff, then bright = 0. Otherwise, bright = 128 (as defined in qsub)..
    leds[k] = CHSV(0, 0, 0);                                        // First set a background colour, but fully saturated.

    // Sparkles!
    if (random(1000) > 996) {
      leds[k] = CHSV(255, 0, 255);
    }

    if (patternId == DISCO_BARBER_1) {
      // original disco barber 1
      // leds[k] += CHSV(hue+k/5, allsat, _brightness);                             // Then assign a hue to any that are bright enough.
      leds[k] += CHSV(hue * 10 + k / 2, allsat, _brightness);                             // Then assign a hue to any that are bright enough.
    } else {
      leds[k] += CHSV(hue * -20 + k / 4, allsat, _brightness);                       // Then assign a hue to any that are bright enough.
    }
  }
 }

void loop () {
  if (!holdPattern) {
    EVERY_N_MILLISECONDS(rotationInMillseconds) {
      firstRun = true;
      patternId += 1;
      if (patternId > maxPatternId) {
        patternId = 1;
      }
    }
  }

  if (patternId == RAINBOW || patternId == RAINBOW_2 || patternId == RAINBOW_3) {
    confetti();
  } else if (patternId == DISCO_BARBER_1 || patternId == DISCO_BARBER_2) {
    discoBarber();
  } else if (patternId == JUGGLE) {
    juggle();
  }

  firstRun = false;

  show_at_max_brightness_for_power();
}
{'fraction_non_alphanumeric': 0.10455246913580248, 'fraction_numerical': 0.0349537037037037, 'mean_word_length': 1.7700363325496902, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 84, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4955117', 'n_tokens_mistral': 4578, 'n_tokens_neox': 4074, 'n_words': 1303}