Skip to content

Instantly share code, notes, and snippets.

@atuline
Last active May 9, 2021 13:20
Show Gist options
  • Save atuline/02e71a57636498d382e276311b328e53 to your computer and use it in GitHub Desktop.
Save atuline/02e71a57636498d382e276311b328e53 to your computer and use it in GitHub Desktop.
Basic Fade In/Out
/*
* File: basicfadein
*
* By: Andrew Tuline
*
* Date: April, 2019
*
* Based previous work (namely twinklefox) by Mark Kriegsman, this program shows how you can fade-in twinkles by using the fact that a random number generator
* with the same seed will generate the same numbers every time. Combine that with millis and a sine wave and you have twinkles fading in/out.
*
* Consider this a poor man's version of twinklefox.
*
*/
#include <FastLED.h>
#define LED_DT 12
#define NUM_LEDS 30
uint8_t max_bright = 128;
struct CRGB leds[NUM_LEDS];
void setup() {
LEDS.addLeds<WS2812, LED_DT, GRB>(leds, NUM_LEDS); // Use this for WS2812
FastLED.setBrightness(max_bright);
} // setup()
void loop() {
basicfadein();
FastLED.show();
} // loop()
void basicfadein() {
random16_set_seed(535); // The randomizer needs to be re-set each time through the loop in order for the 'random' numbers to be the same each time through.
for (int i = 0; i<NUM_LEDS; i++) {
uint8_t fader = sin8(millis()/random8(10,20)); // The random number for each 'i' will be the same every time.
uint8_t colr = random()+millis()/100; // Make a random colour.
leds[i] = CHSV(colr,255, fader); // Now, let's assign to CHSV values and rotate the colour.
}
} // basicfadein()
@thisisfel1x
Copy link

Is it possible to change the speed of the effect?

@atuline
Copy link
Author

atuline commented May 9, 2021

Yes. See line 3509 at: https://github.com/atuline/WLED/blob/8effa1370a539506f907f834a42692dff807f6f6/wled00/FX.cpp#L3509

Change SEGMENT.speed and SEGMENT.intensity for values ranging between 0 and 255, i.e.

uint8_t speed = analogRead(A5)/4;

Note that the other version uses the NeoPixelBus method of addressing the LED's. So, you just need to combine the original sketch with the speed/intensity changes.

@thisisfel1x
Copy link

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment