Time between fades

I am wanting to delay the fade time between two different colours using WS2812B leds, this is what I have so far which is working fine

#include <FastLED.h>
#define LED_PIN 11
#define NUM_LEDS 18
CRGB leds[NUM_LEDS];

int fadeAmount = 15;
int brightness = 0;
void setup() {
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
}

void loop() {
  brightness = brightness + fadeAmount;
  if(brightness == 0 || brightness == 255)
  {
    fadeAmount = -fadeAmount;
  }
  for(int i=0;i<17;i++){
    leds[i] = CRGB(0, 255, 60);
    leds[i].fadeLightBy(brightness);
    FastLED.show();
    delay(100);
  }
  for(int i=0;i<17;i++){
    leds[i] = CRGB(0, 0, 255);
    leds[i].fadeLightBy(brightness);
    FastLED.show();
    delay(100);
  }
}

so this is where the delay() is. make 100 a variable and find a way to change that variable (a potentiometer connected to A0 and use an analogRead() and possibly a map() to get the range you want)

    delay(map(analogRead(A0), 0, 1023, 1, 200)); // wait between 1ms and 200ms depending on potentiometer's position

side note, don't test for perfect equality
if (brightness == 0 || brightness == 255)
you are lucky here that 255 is a multiple of 15. use
if (brightness <= 0 || brightness >= 255)
and adjust the value if you went outside [0, 255]

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.