LED Strip wont shine as bright after void-change - I have to reset every time

Hi guys,

I'm fairly new to coding and arduino and my first project is quite ambitious: I want to build a plague-doctor mask with different light-show-functions for this years helloween-party!

I spend like 15 hours to come to the point I am currently at and now I got no idea at all where the problem could be...

My test-schedules (which brought up the problem) is as followed:

  1. push the button (onButtonPin = 3) for a few seconds
  2. let the afterflow faint out (cool effect in my opinion, even tho I'm not to sure where it is coming from)
  3. turn up the potentiometer a bit and enjoy the pulsing.
  4. fully turn down the potentiomenter
  5. press the button again.

Step for is where the problem - as mentioned in the title - shows up.
The white light wont come up a bright as before - if it comes up at all!

I hope my code is readable.

I'm thankful for every tip and help you can give me to fix this!

#include <FastLED_NeoPixel.h>

#define NUM_LEDS 50
CRGB leds[NUM_LEDS];
#define PIN 6

const int onButtonPin = 3;

const int potPin = A0;

int potValue = 0;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(50, PIN, NEO_GRB + NEO_KHZ800);



void setup()
{
  FastLED.addLeds<WS2812, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  strip.begin();
  strip.setBrightness(85);  // Lower brightness and save eyeballs!
  strip.show(); // Initialize all pixels to 'off
  pinMode(onButtonPin,INPUT);
  pinMode(potPin,INPUT);
  potValue = analogRead(potPin)*4;
}

void loop() {
  if (digitalRead(onButtonPin)==HIGH){
    Fire(50,120,15);
  }
  else if (analogRead(potPin)>50) {
    Serial.println(analogRead(potPin));
    Poison();
  }
  else {
    Fire(0,0,0);
  }
}
//https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/#LEDStripEffectFire modified
void Fire(int Cooling, int Sparking, int SpeedDelay) {
  static byte heat[NUM_LEDS];
  int cooldown;
 
  // Step 1.  Cool down every cell a little
  for( int i = 0; i < NUM_LEDS; i++) {
    cooldown = random(0, ((Cooling * 10) / NUM_LEDS) + 2);
   
    if(cooldown>heat[i]) {
      heat[i]=0;
    } 
    else {heat[i]=heat[i]-cooldown;    }
  }
 
  // Step 2.  Heat from each cell drifts 'up' and diffuses a little
  for( int k= NUM_LEDS - 1; k >= 2; k--) {
    heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2]) / 3;
  }
   
  // Step 3.  Randomly ignite new 'sparks' near the bottom
  if( random(255) < Sparking ) {
    int y = random(7);
    heat[y] = heat[y] + random(160,255);
    //heat[y] = random(160,255);
  }

  // Step 4.  Convert heat to LED colors
  for( int j = 0; j < NUM_LEDS; j++) {
    setPixelHeatColor(j, heat[j] );
  }

  showStrip();
  delay(SpeedDelay);
}

void setPixelHeatColor (int Pixel, byte temperature) {
  // Scale 'heat' down from 0-255 to 0-191
  byte t192 = round((temperature/255.0)*191);
 
  // calculate ramp up from
  byte heatramp = t192 & 0x3F; // 0..63
  heatramp <<= 2; // scale up to 0..252
 
  // figure out which third of the spectrum we're in:
  if( t192 > 0x80) {                     // hottest
    setPixel(Pixel, heatramp-200, heatramp-200, heatramp-200);
  } else if( t192 > 0x40 ) {             // middle
    setPixel(Pixel, heatramp-200, heatramp-200, heatramp-200);
  } else {                               // coolest
    setPixel(Pixel, heatramp, heatramp, heatramp);
  }
}

void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
 #endif
}

void setPixel(int Pixel, byte red, byte green, byte blue) {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.setPixelColor(Pixel, strip.Color(red, green, blue));
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
 #endif
}

void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
  }
  showStrip();
}

void Poison(){
//Written by: Jason Yandell
  potValue = analogRead(potPin);
  int TOTAL_LEDS = 100;
  float MaximumBrightness = map(potValue,0,1023,0,254);
  float SpeedFactor = 0.01; // I don't actually know what would look good
  float StepDelay = 1; // ms for a step delay on the lights

// Make the lights breathe
  for (int x = 0; x < 65535; x++) {
    Serial.println(x);
    potValue = analogRead(potPin);
    int TOTAL_LEDS = 100;
    float MaximumBrightness = map(potValue,0,1023,0,254);
// Intensity will go from 10 - MaximumBrightness in a "breathing" manner
    float intensity = MaximumBrightness /2.0 * (1.0 + sin(SpeedFactor * x));
    strip.setBrightness(intensity);
    if (potValue < 50){
      x = 0;
      strip.show();
    break;
  }
// Now set every LED to that color
  for (int ledNumber=0; ledNumber<TOTAL_LEDS; ledNumber++) {
    strip.setPixelColor(ledNumber,0, 100, 0);
  }

  strip.show();
//Wait a bit before continuing to breathe
  delay(StepDelay);

  }
}

What does "void-change" mean?

Oops.

(Assuming this is an AVR - you forgot to mention which device you're using)

"void-change" meant the switch between Fire() and Poison()

I didn't find a better word

AHH, sorry!!

I'm using an Arduino Uno R3.

The mentioned code-part is prewritten by another coder (mentioned in the comment).

Presumably the code was written for a processor where an int can successfully represent 65535.
Unlike a Uno.

Try changing it to 32766.

checked it, didn't help unfortunately. set it down to 5000. didn't help either.

The test-time is too sure for the code to ramp up to those values.

I FOUND IT!!

The brightness was reducted, due to the set.brightness(intensity) in the void Poison().

Fixed by altering the if-part of the loop.

void loop() {
  if (digitalRead(onButtonPin)==HIGH){
    strip.show();
    *strip.setBrightness(85);*
    Fire(50,120,15);
  }
  else if (analogRead(potPin)>50) {
    strip.show();
    Serial.println(analogRead(potPin));
    Poison();
  }
  else {
    strip.show();
    Fire(0,0,0);
  }
}