Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #define NUM_LEDS 30
- #define LED_PIN 12
- #define BRIGHTNESS 100
- CRGB leds[NUM_LEDS];
- uint8_t ColorIndex[NUM_LEDS];
- DEFINE_GRADIENT_PALETTE (BlueAndPurp)
- {
- 0, 0, 212, 255, //Cyan
- 61, 96, 4, 192, //Purp
- 125, 9, 9, 121, //Dark Blue
- 194, 96, 4, 192, //Purp
- 255, 0, 212, 255, //Cyan
- };
- CRGBPalette16 myPal = BlueAndPurp;
- void setup()
- {
- Serial.begin(115200);
- LEDS.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS); // Use this for WS2801 or APA102
- FastLED.setBrightness(BRIGHTNESS);
- // This is required by withArray(), but not required by withoutArray().
- for(int i = 0; i < NUM_LEDS; i++) ColorIndex[i] = random8();
- }
- void loop() {
- // withArray();
- withoutArray();
- FastLED.show();
- }
- // This method requires an initializer AND an array to store state information.
- void withArray() {
- for(int i = 0; i < NUM_LEDS; i++) {
- leds[i] = ColorFromPalette(myPal, ColorIndex[i], 255);
- if(i==0) Serial.println(ColorIndex[i]);
- }
- EVERY_N_MILLISECONDS(10) {
- for(int i = 0; i < NUM_LEDS; i++) ColorIndex[i]++;
- }
- }
- // This method doesn't require an initializer OR an array to store state information.
- void withoutArray() {
- random16_set_seed(535);
- for(int i = 0; i < NUM_LEDS; i++) {
- leds[i] = ColorFromPalette(myPal, random8()+millis()/10, 255);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement