<commit_before>//
// This program is for the Adafruit LED Belt kit.
//    http://www.adafruit.com/products/332
//
// Here is the LED strip.  
//    http://www.adafruit.com/products/306
//
// The microcontroller is the Adafruit ATMega32u4 breakout board.
//    http://www.adafruit.com/products/296
//
// Install Teensyduino to upload programs onto your board.
//    http://learn.adafruit.com/digital-led-belt/upload-the-test-sketch
//
// NOTE:  The LED strip in the belt kit uses LPD8806 chips to control the LEDs.
// For other strips with other chips there are other libraries, for example 
// this WP2811 based strip instead which uses "Adafruit_NeoPixel.h" instead of "LPD8806.h". 
//    http://www.adafruit.com/products/1376
//


#include "LPD8806.h"
#include "SPI.h"



// Example to control LPD8806-based RGB LED Modules in a strip!
/*****************************************************************************/
#define MAX_COLOR 127
#define NUM_PIXELS 32


#if defined(USB_SERIAL) || defined(USB_SERIAL_ADAFRUIT)
// this is for teensyduino support
int dataPin = 2;
int clockPin = 1;
#else 
// these are the pins we use for the LED belt kit using
// the Leonardo pinouts

// PMA: I'm pretty sure this is what our Adafruit "atmega32u4 breakout"

// Here is our wonderful microcontroller:
// http://www.adafruit.com/products/296


int dataPin = 16;
int clockPin = 15;
#endif

// Set the first variable to the NUMBER of pixels. 32 = 32 pixels in a row
// The LED strips are 32 LEDs per meter but you can extend/cut the strip
LPD8806 strip = LPD8806(NUM_PIXELS, dataPin, clockPin);



void setup() {
  
//  Serial.begin(9600);
  
  // Start up the LED strip
  strip.begin();

  // Update the strip, to start they are all 'off'
  strip.show();
}

///
// function prototypes, keep here!
///
void clearStrip();
void strobeFadeOut(uint8_t red, uint8_t green, uint8_t blue, float brightnessScale, uint8_t strobesPerSec);

///
// Adafruit gave us these ones for starters:
///
void colorChase(uint32_t c, uint8_t wait);
void colorWipe(uint32_t c, uint8_t wait);
void dither(uint32_t c, uint8_t wait);
void scanner(uint8_t r, uint8_t g, uint8_t b, uint8_t wait);
void wave(uint32_t c, int cycles, uint8_t wait);
void rainbowCycle(uint8_t wait);
uint32_t Wheel(uint16_t WheelPos);

void loop() {

  strobeFadeOut(MAX_COLOR, MAX_COLOR, 0, 0.01, 1);
  
}

void strobeFadeOut(uint8_t red, 
                   uint8_t green,
                   uint8_t blue,
                   float brightnessScale,
                   uint8_t strobesPerSec) {
  // Fade out
  
  double colorScale = 1.0;
  double minColorScale = 0.0005;
  double decay = 0.1;
  int i;
  uint16_t fadeWaitTime = 5; //strobesPerSec * 1000 / 8;  // cheating on the math here...how do you count how many times you can divide a number by 2 before it goes less than zero?
//  uint16_t totalFadeTime = 0;

  while (colorScale > minColorScale) {
    colorScale = colorScale - (colorScale * decay);// float(currentBrightness / originalBrightness * 0.01);
    
    double s = colorScale * brightnessScale;
    int redScaled = (red * s);
    int greenScaled = (green * s);
    int blueScaled = (blue * s);
  Serial.print("s: ");
  Serial.println(colorScale);
//  Serial.print("red: ");
//  Serial.println(redScaled);


    for (i=0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, strip.Color(redScaled, greenScaled, blueScaled));
    }
    
    strip.show();
    delay(fadeWaitTime);    
    
    fadeWaitTime = fadeWaitTime - (fadeWaitTime * decay * 10);
  }

  Serial.println("clearing");
    for (i=0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, strip.Color(0, 0, 0));
    }
    
    strip.show();

//  clearStrip();
  delay(2000);
}

void loopEverything() {

  // Send a simple pixel chase in...
  colorChase(strip.Color(127,127,127), 20); // white
  colorChase(strip.Color(127,0,0), 20);     // red
  colorChase(strip.Color(127,127,0), 20);   // yellow
  colorChase(strip.Color(0,127,0), 20);     // green
  colorChase(strip.Color(0,127,127), 20);   // cyan
  colorChase(strip.Color(0,0,127), 20);     // blue
  colorChase(strip.Color(127,0,127), 20);   // magenta

  // Fill the entire strip with...
  colorWipe(strip.Color(127,0,0), 20);      // red
  colorWipe(strip.Color(0, 127,0), 20);     // green
  colorWipe(strip.Color(0,0,127), 20);      // blue
  colorWipe(strip.Color(0,0,0), 20);        // black

  // Color sparkles
  dither(strip.Color(0,127,127), 50);       // cyan, slow
  dither(strip.Color(0,0,0), 15);           // black, fast
  dither(strip.Color(127,0,127), 50);       // magenta, slow
  dither(strip.Color(0,0,0), 15);           // black, fast
  dither(strip.Color(127,127,0), 50);       // yellow, slow<commit_msg>LED belt kit's strobeFadeOut() now how a configurable exponential decay.<commit_after>//
// This program is for the Adafruit LED Belt kit.
//    http://www.adafruit.com/products/332
//
// Here is the LED strip.  
//    http://www.adafruit.com/products/306
//
// The microcontroller is the Adafruit ATMega32u4 breakout board.
//    http://www.adafruit.com/products/296
//
// Install Teensyduino to upload programs onto your board.
//    http://learn.adafruit.com/digital-led-belt/upload-the-test-sketch
//
// NOTE:  The LED strip in the belt kit uses LPD8806 chips to control the LEDs.
// For other strips with other chips there are other libraries. For example 
// this WP2811 based strip uses "Adafruit_NeoPixel.h" instead of "LPD8806.h". 
//    http://www.adafruit.com/products/1376
//


#include "LPD8806.h"
#include "SPI.h"



// Example to control LPD8806-based RGB LED Modules in a strip!
/*****************************************************************************/
#define MAX_COLOR 127
#define NUM_PIXELS 32


#if defined(USB_SERIAL) || defined(USB_SERIAL_ADAFRUIT)
// this is for teensyduino support
int dataPin = 2;
int clockPin = 1;
#else 
// these are the pins we use for the LED belt kit using
// the Leonardo pinouts

// PMA: I'm pretty sure this is what our Adafruit "atmega32u4 breakout"

// Here is our wonderful microcontroller:
// http://www.adafruit.com/products/296


int dataPin = 16;
int clockPin = 15;
#endif

// Set the first variable to the NUMBER of pixels. 32 = 32 pixels in a row
// The LED strips are 32 LEDs per meter but you can extend/cut the strip
LPD8806 strip = LPD8806(NUM_PIXELS, dataPin, clockPin);



void setup() {
  
//  Serial.begin(9600);
  randomSeed(analogRead(0));
  
  // Start up the LED strip
  strip.begin();

  // Update the strip, to start they are all 'off'
  strip.show();
}

///
// function prototypes, keep here!
///
void clearStrip();
void strobeFadeOut(uint8_t red, uint8_t green, uint8_t blue, float brightnessScale, float strobesPerSecond, uint16_t darkMillis);

///
// Adafruit gave us these ones for starters:
///
void colorChase(uint32_t c, uint8_t wait);
void colorWipe(uint32_t c, uint8_t wait);
void dither(uint32_t c, uint8_t wait);
void scanner(uint8_t r, uint8_t g, uint8_t b, uint8_t wait);
void wave(uint32_t c, int cycles, uint8_t wait);
void rainbowCycle(uint8_t wait);
uint32_t Wheel(uint16_t WheelPos);

void loop() {

  // 20 hz is probably the craziest you'd want.
//  strobeFadeOut(MAX_COLOR, MAX_COLOR, 0, 1.0, 20, 0);

  strobeFadeOut(random(MAX_COLOR/3)+MAX_COLOR/3, // red
                random(MAX_COLOR/3), // green
                random(MAX_COLOR/3), // blue
                (random(30) + 60) / 100.0, // brightness scale 0.0 is dark, 1.0 is bright
                0.66,   // strobes per second
                100);  // millis between strobes
  
}

void strobeFadeOut(uint8_t red, 
                   uint8_t green,
                   uint8_t blue,
                   float brightnessScale,
                   float strobesPerSecond,
                   uint16_t darkMillis) {
  // Fade out
  
/*
//
// Exponential decay:
//  	x = initial * exp(k*t)
//
// where initial is the scale value 1.0
// where x is the exponentially decreased scale value at time t
// where t is milliseconds from 0 - 1000
// where k is the decay factor

---------------------------------------
double k = ln(minScale) / msPerStrobe;
k = -0.006907  for msPerStrobe:1000
---------------------------------------
*/

  unsigned long t1, t2;
  float minScale = 0.0001;
  float msPerStrobe = 1000.0 / strobesPerSecond;
  double decay = log(minScale) / msPerStrobe;
//  float t = log(minScale) / decay;
  
  double colorScale = 1.0;
  int i;
  float diff;

  t1 = millis();  
  while (colorScale > (minScale*1.0)) {

    t2 = millis();
    diff = t2 - t1;
    colorScale = 1.0 * exp(decay * diff);
    
    double s = colorScale * brightnessScale;
    int redScaled = (red * s);
    int greenScaled = (green * s);
    int blueScaled = (blue * s);
//    Serial.print("s: ");
//    Serial.println(colorScale);
//    Serial.print("diff: ");
//    Serial.println(diff);
//    Serial.print("decay: ");
//    Serial.println(decay);

    for (i=0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, strip.Color(redScaled, greenScaled, blueScaled));
    }

    strip.show();
    delay(1);
  }

  for (i=0; i < strip.numPixels(); i++) {
//    strip.setPixelColor(i, strip.Color(MAX_COLOR, MAX_COLOR, MAX_COLOR));
    strip.setPixelColor(i, strip.Color(0, 0, 0));
//    delay(darkMillis / strip.numPixels());
  }
    
    strip.show();
  delay(darkMillis);
}

void loopEverything() {

  // Send a simple pixel chase in...
  colorChase(strip.Color(127,127,127), 20); // white
  colorChase(strip.Color(127,0,0), 20);     // red
  colorChase(strip.Color(127,127,0), 20);   // yellow
  colorChase(strip.Color(0,127,0), 20);     // green
  colorChase(strip.Color(0,127,127), 20);   // cyan
  colorChase(strip.Color(0,0,127), 20);     // blue
  colorChase(strip.Color(127,0,127), 20);   // magenta

  // Fill the entire strip with...
  colorWipe(strip.Color(127,0,0), 20);      // red
  colorWipe(strip.Color(0, 127,0), 20);     // green
  colorWipe(strip.Color(0,0,127), 20);      // blue
  colorWipe(strip.Color(0,0,0), 20);        // black

  // Color sparkles
  dither(strip.Color(0,127,127), 50);       // cyan, slow
  dither(strip.Color(0,0,0), 15);           // black, fast
  dither(strip.Color(127,0,127), 50);       // magenta, slow
  dither(strip.Color(0,0,0), 15);           // black, fast
  dither(strip.Color(127,127,0), 50);       // yellow, slow
{'fraction_non_alphanumeric': 0.15704879938032532, 'fraction_numerical': 0.05451200619674671, 'mean_word_length': 2.7793633369923163, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 10, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6191812', 'n_tokens_mistral': 3996, 'n_tokens_neox': 3527, 'n_words': 984}