Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #define COLOR_ORDER BRG
- #define NUM_LEDS_PER_STRIP 60
- #define FRAMES_PER_SECOND 60
- #define MAX_BRIGHTNESS 164 // Thats full on, watch the power!
- #define MIN_BRIGHTNESS 32 // set to a minimum of 25%
- const int FunctionPin = A0; // The Analog input pin to control program selection
- const int InPin1 = A1; // Analog to change variable in programs
- const int InPin2 = A2; // Analog to change variable in programs
- const int InPin3 = A3; // Analog to change variable in programs
- bool gReverseDirection = false;
- CRGB leds[NUM_LEDS_PER_STRIP];
- void setup() {
- // Pylon one
- FastLED.addLeds<APA102, 2, 3, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
- FastLED.addLeds<APA102, 4, 5, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
- FastLED.addLeds<APA102, 6, 7, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
- //Pylon Two
- FastLED.addLeds<APA102, 8, 9, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
- FastLED.addLeds<APA102, 10, 11, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
- FastLED.addLeds<APA102, 12, 13, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
- // Pylon Three
- FastLED.addLeds<APA102, 14, 15, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
- FastLED.addLeds<APA102, 16, 17, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
- FastLED.addLeds<APA102, 18, 19, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
- //Pylon Four
- FastLED.addLeds<APA102, 20, 21, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
- FastLED.addLeds<APA102, 22, 23, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
- FastLED.addLeds<APA102, 24, 25, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
- //Pylon Five
- FastLED.addLeds<APA102, 26, 27, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
- FastLED.addLeds<APA102, 28, 29, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
- FastLED.addLeds<APA102, 30, 31, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
- //Pylon Six
- FastLED.addLeds<APA102, 32, 33, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
- FastLED.addLeds<APA102, 34, 35, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
- FastLED.addLeds<APA102, 36, 37, BGR>(leds, NUM_LEDS_PER_STRIP).setCorrection( TypicalLEDStrip );
- delay(3000); // sanity delay
- }
- int gCurrentPatternNum = map(analogRead(FunctionPin), 0, 1023, 0, 3); // problem area, honestly, throwing things at the wall
- // to see what sticks.
- typedef void (*PatternList[])(); // looked at other code, tried to emulate it
- PatternList gPatterns = {FirePattern, RainbowGlitter, juggle, sinelon};// however once code runs it seems like pot is no
- // longer read and I cant change values
- // uint8_t gCurrentPatternNum = 0; // used to select the pattern
- uint8_t gHue = 0;
- void loop () {
- gPatterns[gCurrentPatternNum]();
- FastLED.show();
- FastLED.delay(1000/FRAMES_PER_SECOND);
- }
- void sinelon()
- {
- // a colored dot sweeping back and forth, with fading trails
- fadeToBlackBy( leds, NUM_LEDS_PER_STRIP, 20);
- int pos = beatsin16( 13, 0, NUM_LEDS_PER_STRIP-1 );
- leds[pos] += CHSV( gHue, 255, 192);
- }
- void juggle() {
- // eight colored dots, weaving in and out of sync with each other
- fadeToBlackBy( leds, NUM_LEDS_PER_STRIP, 20);
- byte dothue = 0;
- for( int i = 0; i < 8; i++) {
- leds[beatsin16( i+7, 0, NUM_LEDS_PER_STRIP-1 )] |= CHSV(dothue, 200, 255);
- dothue += 32;
- }
- }
- void RainbowGlitter ()
- {
- int GlitterPop = map(analogRead(InPin1), 0, 1023, 20, 100);
- // FastLED's built-in rainbow generator
- fill_rainbow( leds, NUM_LEDS_PER_STRIP, gHue, 7);// put your main code here, to run repeatedly:
- addGlitter(GlitterPop);
- }
- void FirePattern()
- {
- // Array of temperature readings at each simulation cell
- static byte heat[NUM_LEDS_PER_STRIP];
- int COOLING = map(analogRead(InPin1), 0, 1023, 20, 100);
- int SPARKING = map(analogRead(InPin2), 0, 1023, 50, 100);
- // Step 1. Cool down every cell a little
- for( int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
- heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / NUM_LEDS_PER_STRIP) + 2));
- }
- // Step 2. Heat from each cell drifts 'up' and diffuses a little
- for( int k= NUM_LEDS_PER_STRIP - 1; k >= 2; k--) {
- heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
- }
- // Step 3. Randomly ignite new 'sparks' of heat near the bottom
- if( random8() < SPARKING ) {
- int y = random8(7);
- heat[y] = qadd8( heat[y], random8(160,255) );
- }
- // Step 4. Map from heat cells to LED colors
- for( int j = 0; j < NUM_LEDS_PER_STRIP; j++) {
- CRGB color = HeatColor( heat[j]);
- int pixelnumber;
- if( gReverseDirection ) {
- pixelnumber = (NUM_LEDS_PER_STRIP-1) - j;
- } else {
- pixelnumber = j;
- }
- leds[pixelnumber] = color;
- }
- }
- void addGlitter( fract8 chanceOfGlitter)
- {
- if( random8() < chanceOfGlitter) {
- leds[ random16(NUM_LEDS_PER_STRIP) ] += CRGB::White;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment