<commit_before>
#define colorcurvesize 8
int colorcurve [colorcurvesize][3] = 
  {
    { 0, 0, 0 },
    { 10, 2, 0 },
    { 31, 14, 2},
    { 58, 33, 5 },
    { 95, 63, 7 },
    { 145, 106, 14 },
    { 195, 171, 32 },
    { 255, 255, 76 }
  };

int oldbrightness = 0;

/* Same as dimThousands, but slowly increases/decreases to end up at the given value */
void goToDimThousands(int brightness) {
  goToDimThousands(brightness,1, false);
}

/* Same as dimThousands, but slowly increases/decreases to end up at the given value */
void goToDimThousands(int brightness, int stepDelayMs, boolean checkPIR) {
//  Serial.print("Dimming from ");  Serial.print(oldbrightness, DEC);
//  Serial.print(" to "); Serial.println(brightness, DEC);

  int inc = 1;
  if (brightness < oldbrightness) {
    inc = -1;
  }
  
  for (int i=oldbrightness; i!=brightness; i = i + inc) {
    dimThousands(i);
    oldbrightness = i;
    delay(stepDelayMs);
    if (checkPIR && hasPIR()) break;
  }  
}


/* 0 = off, 1000 is full brightness */
void dimThousands(int brightness){
  brightness = constrain(brightness, 0, 1000);
  
  // Find the two indices
  float findex = (float) (brightness * (colorcurvesize-1)) / 1000;

  int lowindex = constrain((int) findex,0,colorcurvesize-1);
  int highindex = constrain(lowindex+1,0,colorcurvesize-1);
  
  int red = colorcurve[lowindex][0];
  int green = colorcurve[lowindex][1];
  int blue = colorcurve[lowindex][2];
    
  if (lowindex != highindex) {
    int hred   = colorcurve[highindex][0];
    int hgreen = colorcurve[highindex][1];
    int hblue  = colorcurve[highindex][2];
    
    float ratio = findex - lowindex;
    red   = (int) (0.5 + red   + (ratio * (hred   - red  )));
    green = (int) (0.5 + green + (ratio * (hgreen - green)));
    blue  = (int) (0.5 + blue  + (ratio * (hblue  - blue )));
  }<commit_msg>Working version, with changed resistors and touch timing, and added LDR check when powering off in daylight so that it does not stop at 25% dim.<commit_after>
#define colorcurvesize 8
int colorcurve [colorcurvesize][3] = 
  {
    { 0, 0, 0 },
    { 10, 2, 0 },
    { 31, 14, 2},
    { 58, 33, 5 },
    { 95, 63, 7 },
    { 145, 106, 14 },
    { 195, 171, 32 },
    { 255, 255, 76 }
  };

/* Same as dimThousands, but slowly increases/decreases to end up at the given value */
void goToDimThousands(int brightness) {
  goToDimThousands(brightness,1, false);
}

/* Same as dimThousands, but slowly increases/decreases to end up at the given value */
void goToDimThousands(int brightness, int stepDelayMs, boolean checkPIR) {
//  Serial.print("Dimming from ");  Serial.print(oldbrightness, DEC);
//  Serial.print(" to "); Serial.println(brightness, DEC);

  int inc = 1;
  if (brightness < currentBrightness) {
    inc = -1;
  }
  
  for (int i=currentBrightness; i!=brightness; i = i + inc) {
    dimThousands(i);
    currentBrightness = i;
    delay(stepDelayMs);
    if (checkPIR && hasPIR()) break;
  }  
  currentBrightness = brightness;
}


/* 0 = off, 1000 is full brightness */
void dimThousands(int brightness){
  brightness = constrain(brightness, 0, 1000);
  
  // Find the two indices
  float findex = (float) (brightness * (colorcurvesize-1)) / 1000;

  int lowindex = constrain((int) findex,0,colorcurvesize-1);
  int highindex = constrain(lowindex+1,0,colorcurvesize-1);
  
  int red = colorcurve[lowindex][0];
  int green = colorcurve[lowindex][1];
  int blue = colorcurve[lowindex][2];
    
  if (lowindex != highindex) {
    int hred   = colorcurve[highindex][0];
    int hgreen = colorcurve[highindex][1];
    int hblue  = colorcurve[highindex][2];
    
    float ratio = findex - lowindex;
    red   = (int) (0.5 + red   + (ratio * (hred   - red  )));
    green = (int) (0.5 + green + (ratio * (hgreen - green)));
    blue  = (int) (0.5 + blue  + (ratio * (hblue  - blue )));
  }
{'fraction_non_alphanumeric': 0.1453503516540766, 'fraction_numerical': 0.04402188069809846, 'mean_word_length': 3.151351351351351, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2523248', 'n_tokens_mistral': 1549, 'n_tokens_neox': 1341, 'n_words': 382}