Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This code creates a spinning circle that is oriented in a horizontal plane like a bicycle wheel laying on its side. A single LED appears to rotate around the circumference and there is one light in the middle. It runs on an ordinary straight addressable LED light Strip.
- It creates a very good 3D effect. Derivative works can include multiple circles with different colors and directions, and even figure 8s. Those are left to your imagination.*/
- #include <FastLED.h>
- #define LED_PIN 5
- #define COLOR_ORDER BRG
- #define CHIPSET WS2811
- #define NUM_LEDS 100
- CRGB leds[NUM_LEDS];
- void setup() {
- //delay(3000); // sanity delay
- FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
- FastLED.setBrightness( BRIGHTNESS );
- circle(1);
- }
- /*****************************************************************
- **** circle - uses trig functions to drive a circular orbit ****
- * **************************************************************/
- void circle(int reps)
- {
- int j,xpoint,quarter,color;
- float testx,firstx,lastx,lasty,nextx,nexty,ledpos,lastledpos,brightpos;
- float angle;
- int bright, center;
- center = 50; //positions the center of the circle
- angle = .8; //set this to change the speed of rotation higher numbers are faster (it's degrees of rotation for
- //each show() command loop)
- firstx=lastx= 50; //set this to change the diameter of the circle
- lasty=0; //can be changed but no good reason for it.
- while(reps--)
- {
- for (j=0;j<100;j++)leds[j].setRGB(0,0,0); //sets all the leds to off.
- FastLED.show();
- while(1)
- { //endless loop - need to change this if used with other subroutines
- nextx=(lastx*cos(angle*PI/180)-lasty*sin(angle*PI/180));// These two lines calculate the next
- // point on the circle from any other
- // point on it.
- nexty=(lasty*cos(angle*PI/180)+lastx*sin(angle*PI/180));
- lastledpos = (lastx+NUM_LEDS)/2; // calculates the last led to be lit so that it can be turned off.
- ledpos=(nextx+NUM_LEDS)/2;
- brightpos=(nexty+NUM_LEDS)/2;
- bright = 85 * (brightpos-(center-(firstx/2)))/firstx;//want min brightness when lit led is at back of circle,
- // max brightness when closest to front;
- if ((nextx>0)&&(nexty>0)) quarter = 1;
- if ((nextx<0)&&(nexty>0)) quarter = 2;
- if ((nextx<0)&&(nexty<0)) quarter = 3;
- if ((nextx>0)&&(nexty<0)) quarter = 4;
- // figure out which quarter of the circle we're in
- color = bright*3;
- xpoint=int(ledpos);
- leds[int(lastledpos)].setRGB(0,0,0);
- leds[center].setRGB(0,150,0); //turns on a green dot in the middle of the string
- leds[xpoint].setRGB(0,color,color);
- if(((xpoint>(center-3))&&(xpoint<(center+4)))&&(quarter<3)) //dims dot when moving led passes in front
- {
- leds[center].setRGB(0,0,0);
- }
- if((quarter>2)&&(xpoint == center))leds[center].setRGB(0,150,0);
- lastx=nextx;
- lasty=nexty;
- FastLED.show();
- //delay(100);
- }
- }}
Add Comment
Please, Sign In to add comment