Hello,
I'm new to coding and have done some searching for this, but haven't really found anything that's worked yet. I'm lighting a Lightsaber display and want the LEDs to dim and brighten on a slow loop; kind of like the light is pulsating. Doesn't have to be random for each individual LED or anything, just dim by about half, and then come back up to the original brightness in the span of about a second or two.
Here is my code to just have all the different lights on. I built this off some beginner tutorials I watched, so may be some stuff that's unneeded in there:
#include <FastLED.h>
#define NUM_LEDS 51
#define DATA_PIN 6
#define COLOR_ORDER GRB
#define CHIPSET WS2812B
#define BRIGHTNESS 255
#define VOLTS 5
#define MAX_AMPS 500
CRGB leds [NUM_LEDS];
void setup() {
// put your setup code here, to run once:
FastLED.addLeds<CHIPSET, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setMaxPowerInVoltsAndMilliamps (VOLTS, MAX_AMPS);
FastLED.setBrightness (BRIGHTNESS);
FastLED.clear ();
FastLED.show ();
}
void loop() {
// put your main code here, to run repeatedly:
leds[0] = CRGB(0,255,0);
leds[1] = CRGB(0,255,0);
leds[2] = CRGB(0,255,0);
fadeToBlackBy(&leds[0], 3, 210); //code to fade individual pixel (led #, how many LEDs, amount to fade from 255)
leds[3] = CRGB(255,255,255);
leds[6] = CRGB(0,255,0);
leds[9] = CRGB(255,255,0);
leds[12] = CRGB(0,0,255);
leds[15] = CRGB(255,0,255);
leds[18] = CRGB(255,0,0);
leds[21] = CRGB(255,255,255);
leds[22] = CRGB(255,0,0);
leds[23] = CRGB(255,0,0);
leds[24] = CRGB(255,0,0);
fadeToBlackBy(&leds[22], 3, 210); //code to fade individual pixel (led #, how many LEDs, amount to fade from 255)
leds[25] = CRGB(255,0,0);
leds[26] = CRGB(255,0,0);
leds[27] = CRGB(255,0,0);
leds[28] = CRGB(255,0,0);
fadeToBlackBy(&leds[25], 4, 240); //code to fade individual pixel (led #, how many LEDs, amount to fade from 255)
leds[29] = CRGB(255,0,0);
leds[30] = CRGB(255,0,0);
fadeToBlackBy(&leds[29], 2, 200); //code to fade individual pixel (led #, how many LEDs, amount to fade from 255)
leds[31] = CRGB(100,100,255);
leds[32] = CRGB(100,100,255);
leds[35] = CRGB(100,100,255);
leds[36] = CRGB(100,100,255);
leds[37] = CRGB(100,100,255);
leds[38] = CRGB(100,100,255);
leds[39] = CRGB(100,100,255);
leds[40] = CRGB(100,100,255);
leds[41] = CRGB(100,100,255);
leds[42] = CRGB(100,100,255);
leds[43] = CRGB(100,100,255);
leds[46] = CRGB(100,100,255);
leds[47] = CRGB(100,100,255);
fadeToBlackBy(&leds[31], 17, 200); //code to fade individual pixel (led #, how many LEDs, amount to fade from 255)
leds[48] = CRGB(0,0,255);
leds[49] = CRGB(0,0,255);
leds[50] = CRGB(0,0,255);
FastLED.show();
delay(100);
}
And here is a picture of the display when lit so you can see what it looks like.
Thanks for your help!
