Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #define LED_PIN 5
- #define COLOR_ORDER RBG
- #define CHIPSET WS2811
- #define NUM_LEDS 100
- #define BRIGHTNESS 255
- #define FRAMES_PER_SECOND 150
- //bool gReverseDirection = true;
- CRGB leds[NUM_LEDS];
- void setup() {
- FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
- FastLED.setBrightness( BRIGHTNESS );
- }
- void loop()
- {
- infinity();
- }
- /*******************************************************************
- **** Infinity = makes a figure 8 out of two circles laying flat****
- * *****************************************************************/
- void infinity()
- {
- /*
- Here we have two circles both rotating at the same rate. The dot tracing the circumference of one circle
- is blacked out during the time when the other circle is lit up. This is what creates the figure 8 (or
- if you will, the infinity symbol) Written by Mike Fuller but a lot of credit has to go to the authors of
- FastLED. I had been using a radioshack program to run my LEDs for years and just recently (2020) became
- aware of what FastLED can do. The color handling and that fadeToBlackBy() function are dynamite. I
- could've used the FastLED sin and cos functions but the arduino functions were adequate here.
- I think you could use this scheme to have a 3D serpent run up and down your led string without much work.
- just use smaller circles and more of them.
- */
- boolean fig;
- // These variables are for the right circle
- int j,xpoint,quarter,blue,loopcounter,bright;
- float firstx,lastx,lasty,nextx,nexty,ledpos,lastledpos,brightpos;
- float angle;
- //r parameters***********************These are for the left circle
- int jr,xpointr,quarterr,bluer, countr,brightr;
- float firstxr,lastxr,lastyr,nextxr,nextyr,ledposr,lastledposr,brightposr;
- float angler;
- //Set starting values here
- fig = true; //this variable determines where we are in the figure 8 true if we are on the right.
- angle = -1.2; //set this to change the speed of rotation higher numbers are faster (it's degrees or rotation for
- //each FastLED.show() command loop. Use a negative number to rotate backwards - programming later
- //expects backward rotation.
- firstx=lastx = 40; //set this to change the diameter of the circle
- lasty = 0; //can be changed but no good reason for it here. By setting it at zero you start your
- //circle at the ordered pair coordinate(40,0) [(x,y}]
- //r values*******************for the left circle - why not use "L" you ask?
- angler = -1.2;
- firstxr = lastxr= -40; //here we want the left circle to start at (-40,0) so it hits the midpoint at just the right time
- //also note that both circles must spin at the same rate (same angle)
- lastyr = 0; //starting last "y" position for the left, left circle - not the right one.
- for (j = 0;j < 100; j++)leds[j].setRGB(0,0,0); //sets all the leds to off. I know, theres a function for that.
- while(1)
- {
- while(1)
- { //endless loop - need to change this if used with other subroutines
- nextx = (lastx*cos(angle*PI/180)-lasty*sin(angle*PI/180)); //formulae for next x coordinate and next y coordinate after
- nexty = (lasty*cos(angle*PI/180)+lastx*sin(angle*PI/180)); // "angle" degrees of rotation.
- ledpos = (nextx+140)/2; // calculates where in your array of leds the nextx position is (because next x values go
- // negative as you spin around a circle - so do the y values. Add 140 to keep ledpos from
- // going negative and establishes the center point of the right circle
- brightpos=(nexty+140)/2; // This gives a range of values based on how close to the front the LED is supposed to be
- if ((nextx>0)&&(nexty>0)) quarter = 1; //these lines determine what quadrant on an (x,y) plot the circle is in.
- if ((nextx<0)&&(nexty>0)) quarter = 2;
- if ((nextx<0)&&(nexty<0)) quarter = 3;
- if ((nextx>0)&&(nexty<0)) quarter = 4;
- if (lasty<=0 && nexty>=0) fig=!fig; //This is the trigger that determines which half of the circle is lit
- //only need to set this once and then its go for both circles until it flops.
- bright = 85 * (brightpos-(70-(firstx/2)))/firstx; // setup to give brightest light at middle of front and
- // dim but more or less visible all the way at the back
- blue = 80+(bright*3)*.5 ; // more tweaking on brightness - started off with blue dots
- // never got around to changing the variable name
- xpoint=int(ledpos); // need an integer to index the array of LEDs
- leds[70]=CHSV(25,200,100); //turns on a dot in the middle of the string for the moving dot(s) to pass in front of
- //when the dot is going in front of the center point, and behind it when going around
- //the back of the circle
- if (fig && !(xpoint == 70)) leds[xpoint].setRGB(0,0,0); // this keeps the right circle dark while the dot is passing
- // along the backside of its rotation, when the left circle is
- // on the front of its rotation.
- else
- if (!fig ) //now we want to see the light
- {
- leds[xpoint]= CHSV(192,255,blue);
- leds[xpoint] %= blue;
- }
- if(((xpoint>67)&&(xpoint<77))&&(quarter<3)&&!fig) //Turn the center point off as we pass by
- {
- leds[70].setRGB(0,0,0);
- if (fig) leds[xpoint].setRGB(0,0,0);
- }
- if((quarter>2)&&(xpoint == 70))leds[70]= CHSV(25,200,100); //keeps center point light on here.
- lastx=nextx;
- lasty=nexty;
- //r parameters *************************************************************************
- nextxr = (lastxr*cos(angler*PI/180)-lastyr*sin(angler*PI/180));
- nextyr = (lastyr*cos(angler*PI/180)+lastxr*sin(angler*PI/180));
- ledposr=(nextxr+60)/2;
- brightposr=(nextyr+60)/2;
- if ((nextxr>0)&&(nextyr>0)) quarterr = 1;
- if ((nextxr<0)&&(nextyr>0)) quarterr = 2;
- if ((nextxr<0)&&(nextyr<0)) quarterr = 3;
- if ((nextxr>0)&&(nextyr<0)) quarterr = 4;
- brightr = 85 * (brightposr-(30-(firstxr/2)))/firstxr;
- bluer = 80+(brightr*3)*.5 ;
- xpointr=int(ledposr);
- leds[30]= CHSV(25,200,100);
- if (fig)
- {
- //here's where we want to see the light- opposite of right circle
- leds[xpointr]= CHSV(192,255,bluer);
- leds[xpointr]%=bluer;
- }
- else
- if (!fig && !(xpointr==30)) leds[xpointr].setRGB(0,0,0);
- if(((xpointr>24)&&(xpointr<36))&&(quarterr>3)&&fig)
- {
- leds[xpointr]= CHSV(192,255,bluer);
- leds[30].setRGB(0,0,0);
- }
- if((quarterr<3)&&(xpointr == 30))
- {
- leds[30] = CHSV(25,200,100);
- }
- lastxr=nextxr;
- lastyr=nextyr;
- fadeToBlackBy(leds, NUM_LEDS,40);
- FastLED.show(); //called once for each loop through. The X position of the lit led does not change with every loop.
- //it stays the same for a brief time at the right and left edges of each circle as would be expected.
- }
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement