Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- FastLED Samples for Neopixel Ring
- Original sketches from the FastLED community
- Some comments by Gyro Gearloose :)
- */
- #include <FastLED.h>
- #define DATA_PIN 6
- //#define CLK_PIN 8
- //#define LED_TYPE LPD8806
- //#define COLOR_ORDER GRB
- //#define LED_TYPE APA102
- //#define COLOR_ORDER GBR
- #define LED_TYPE WS2811
- #define COLOR_ORDER GRB // check your color order !
- #define LED_COUNT 24
- CRGB leds[LED_COUNT];
- #define BRIGHTNESS 200
- #define FRAMES_PER_SECOND 120
- int BOTTOM_INDEX = 0;
- int TOP_INDEX = int(LED_COUNT/2);
- int EVENODD = LED_COUNT%2;
- int ledsX[LED_COUNT][3]; //-ARRAY FOR COPYING WHATS IN THE LED STRIP CURRENTLY (FOR CELL-AUTOMATA, MARCH, ETC)
- int thisdelay = 20; //-FX LOOPS DELAY VAR
- int thisstep = 10; //-FX LOOPS DELAY VAR
- int thishue = 0; //-FX LOOPS DELAY VAR
- int thissat = 255; //-FX LOOPS DELAY VAR
- int max_bright = 255; //-SET MAX BRIGHTNESS TO 1/2
- int thisindex = 0; //-SET SINGLE LED VAR
- int thisRED = 0;
- int thisGRN = 0;
- int thisBLU = 0;
- //---LED FX VARS
- int idex = 0; //-LED INDEX (0 to LED_COUNT-1
- int ihue = 0; //-HUE (0-255)
- int ibright = 0; //-BRIGHTNESS (0-255)
- int isat = 0; //-SATURATION (0-255)
- int bouncedirection = 0; //-SWITCH FOR COLOR BOUNCE (0-1)
- float tcount = 0.0; //-INC VAR FOR SIN LOOPS
- int lcount = 0; //-ANOTHER COUNTING VAR
- //---FIND INDEX OF ANTIPODAL OPPOSITE LED
- int antipodal_index(int i) {
- int iN = i + TOP_INDEX;
- if (i >= TOP_INDEX) {iN = ( i + TOP_INDEX ) % LED_COUNT; }
- return iN;
- }
- void setup() {
- delay(2000); // 2 second delay for recovery
- // tell FastLED about the LED strip configuration
- //FastLED.addLeds<LED_TYPE, DATA_PIN, CLOCK_PIN, COLOR_ORDER, DATA_RATE_MHZ(5)>(leds, LED_COUNT); // you can lower the data rate (1..5 MHZ)
- //FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, LED_COUNT).setCorrection(TypicalLEDStrip);
- FastLED.addLeds<LED_TYPE,DATA_PIN, COLOR_ORDER>(leds, LED_COUNT).setCorrection(DirectSunlight); //CarbonArc
- // set master brightness control
- FastLED.setBrightness(BRIGHTNESS);
- }
- // List of patterns to cycle through. Each is defined as a separate function below.
- typedef void (*SimplePatternList[])();
- SimplePatternList gPatterns = {
- ems_lightsONE,
- ems_lightsALL,
- pulse_one_color_all,
- ems_lightsSTROBE,
- sinelon,
- kitt // last has no comma
- } ;
- uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
- uint8_t gHue = 0; // rotating "base color" used by many of the patterns
- void loop()
- {
- // Call the current pattern function once, updating the 'leds' array
- gPatterns[gCurrentPatternNumber]();
- // send the 'leds' array out to the actual LED strip
- FastLED.show(); // taken out for Power Management
- // insert a delay to keep the framerate modest
- FastLED.delay(1000/FRAMES_PER_SECOND);
- EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
- EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow;
- // if you take this out the color will stay red in the sinelon function
- }
- #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
- void nextPattern()
- {
- // add one to the current pattern number, and wrap around at the end
- gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
- }
- void one_color_all(int cred, int cgrn, int cblu) { //-SET ALL LEDS TO ONE COLOR
- for(int i = 0 ; i < LED_COUNT; i++ ) {
- leds[i].setRGB( cred, cgrn, cblu);
- }
- }
- void one_color_allHSV(int ahue) { //-SET ALL LEDS TO ONE COLOR (HSV)
- for(int i = 0 ; i < LED_COUNT; i++ ) {
- leds[i] = CHSV(ahue, thissat, 255);
- }
- }
- void ems_lightsONE() { //-m7-EMERGENCY LIGHTS (TWO COLOR SINGLE LED)
- idex++;
- if (idex >= LED_COUNT) {idex = 0;}
- int idexR = idex;
- int idexB = antipodal_index(idexR);
- int thathue = (thishue + 160) % 255; // blue
- for(int i = 0; i < LED_COUNT; i++ ) {
- if (i == idexR) {leds[i] = CHSV(thishue, thissat, 255);}
- // else if (i == idexB) {leds[i] = CHSV(thathue, thissat, 255);} // if you want blue
- else if (i == idexB) {leds[i] = CRGB(0,0,0);}
- else {leds[i] = CHSV(0, 0, 0);}
- }
- FastLED.show();
- delay(thisdelay + 10); // set here the speed
- }
- void ems_lightsALL() { //-m8-EMERGENCY LIGHTS (TWO COLOR SOLID)
- idex++;
- if (idex >= LED_COUNT) {idex = 0;}
- int idexR = idex;
- int idexB = antipodal_index(idexR);
- int thathue = (thishue + 160) % 255;
- leds[idexR] = CHSV(thishue, thissat, 255);
- // leds[idexB] = CHSV(thathue, thissat, 255); // if you want blue
- leds[idexB] = CRGB(0,0,0);
- FastLED.show();
- delay(thisdelay);
- }
- void pulse_one_color_all() { //-m10-PULSE BRIGHTNESS ON ALL LEDS TO ONE COLOR
- if (bouncedirection == 0) {
- ibright++;
- if (ibright >= 255) {bouncedirection = 1;}
- }
- if (bouncedirection == 1) {
- ibright = ibright - 1;
- if (ibright <= 1) {bouncedirection = 0;}
- }
- for(int idex = 0 ; idex < LED_COUNT; idex++ ) {
- leds[idex] = CHSV(thishue, thissat, ibright);
- }
- LEDS.show();
- delay(thisdelay-10
- );
- }
- void ems_lightsSTROBE() { //-m26-EMERGENCY LIGHTS (STROBE LEFT/RIGHT)
- thisdelay = thisdelay + 20;
- int thishue = 0;
- int thathue = (thishue + 160) % 255;
- for(int x = 0 ; x < 5; x++ ) {
- for(int i = 0 ; i < TOP_INDEX; i++ ) {
- leds[i] = CHSV(thishue, thissat, 255);
- }
- FastLED.show(); delay(thisdelay);
- one_color_all(0, 0, 0);
- FastLED.show(); delay(thisdelay);
- }
- for(int x = 0 ; x < 5; x++ ) {
- for(int i = TOP_INDEX ; i < LED_COUNT; i++ ) {
- leds[i] = CHSV(thathue, thissat, 255);
- }
- FastLED.show(); delay(thisdelay);
- one_color_all(0, 0, 0);
- FastLED.show(); delay(thisdelay);
- }
- thisdelay = 20;
- }
- void kitt() { //-m28-KNIGHT INDUSTIES 2000
- int rand = random(0, TOP_INDEX);
- for(int i = 0; i < rand; i++ ) {
- leds[TOP_INDEX+i] = CHSV(thishue, thissat, 255);
- leds[TOP_INDEX-i] = CHSV(thishue, thissat, 255);
- FastLED.show();
- delay(thisdelay-10/rand);
- }
- for(int i = rand; i > 0; i-- ) {
- leds[TOP_INDEX+i] = CHSV(thishue, thissat, 0);
- leds[TOP_INDEX-i] = CHSV(thishue, thissat, 0);
- FastLED.show();
- delay(thisdelay-10/rand);
- }
- }
- void sinelon()
- {
- // a colored dot sweeping back and forth, with fading trails
- fadeToBlackBy( leds, LED_COUNT, 20);
- int pos = beatsin16(13,0,LED_COUNT);
- leds[pos] += CHSV( gHue, 255, 192);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement