G+_Kyle Boyington Posted May 11, 2018 Share Posted May 11, 2018 I am having a problem that should be super simple, I am sure I am missing something! Is there an easy way to have a led move in a circle around a WS2812 ring? I wanted it to look something like half of the ring was dark and a 'streak' was making a continuous circle around the ring, with a fading tail. Is this going to be hard to pull off? Link to comment Share on other sites More sharing options...
G+_Jim Hofmann Posted May 11, 2018 Share Posted May 11, 2018 Checkout Instructables, there are a number of examples. instructables.com - Instructables Search Results Most mount the electronics and battery on the spinning disk or use a slip ring. Good luck Link to comment Share on other sites More sharing options...
G+_Brent Vrieze Posted May 11, 2018 Share Posted May 11, 2018 I think some of the sample code with FastLED would do this as well. Link to comment Share on other sites More sharing options...
G+_Jim Hofmann Posted May 11, 2018 Share Posted May 11, 2018 I've wanted to do some POV shtuff and thought of using WS281x LEDs but from what I've read they don't respond fast enough to do POV. Need to do the math one of these days. Link to comment Share on other sites More sharing options...
G+_Jim Hofmann Posted May 11, 2018 Share Posted May 11, 2018 I reread your post. I think I misunderstood what you are trying to do. If I understand, You want a ring of WS2812s, the first at full brightness, next 1/2 brightness, 1/4, 1/8, ... with the rest off. Then just advance the sequence to start on the next LED. It should be easy with an array and a couple For loops. Sorry about the confusion. Link to comment Share on other sites More sharing options...
G+_Kyle Boyington Posted May 14, 2018 Author Share Posted May 14, 2018 Jim Hofmann Thanks for that. I didn't think moving the whole array forward! Link to comment Share on other sites More sharing options...
G+_Mark Olson Posted June 2, 2018 Share Posted June 2, 2018 The FastLED examples assume you have a linear arrangement of LEDs, so using them with a circular arrangement requires some calculations, usually involving modulo arithmetic. The sinelon() code from the Demo Reel 100 is close to what you describe, but would need mods to go in a circle: github.com - FastLED The idea in the code is that the sinelon() routine is called repeatedly, maybe 60 times a second. The code that calls sinelon() also does the calls to display the resulting LEDs. Here is a line-by-line commentary on sinelon (only three lines) 1) First all dots fade a bit with the fadeToBlackBy() routine 2) Then the position of the LED to brighten is calculated using the beatsin16() routine 3) Then that LED is set to the desired color, using a global gHue variable manipulated outside of sinelon(). If you replace the beatsin16() routine with something of your own, something that moves around inside your circle at an appropriate rate, that could do the trick. If desired, you could use a particular color if desired instead of the changing gHue method in the DemoReel100.ino code. As a quick example, here is some code that increments around a circle of LEDs with NUM_LEDS defined as the total number of LEDs (for instance, if the ring has 32 LEDs, NUM_LEDS is defined as 32). It is designed as a replacement line for the "int pos = beatsin16( 13, 0, NUM_LEDS-1 );" in the sinelon() code: int pos = nextincircle(NUM_LEDS); Later there would be the definition of the routine nextincircle(): int nextincircle(int num_leds) { // calculate next LED position in the circle using modulo arithmetic static int pos_b4 = 0; // need to remember where we ended up new_pos = (1 + pos_b4) % num_leds; // calculate new position, going back to zero after hitting max pos_b4 = new_pos; // could have done that in one line return(new_pos); // return the new position } Link to comment Share on other sites More sharing options...
G+_Mark Olson Posted June 2, 2018 Share Posted June 2, 2018 oops! left out a definition in my example code above; here is the correction: int nextincircle(int num_leds) { // calculate next LED position in the circle using modulo arithmetic static int pos_b4 = 0; // need to remember where we ended up int new_pos = (1 + pos_b4) % num_leds; // calculate new position, going back to zero after hitting max pos_b4 = new_pos; // could have done that in one line return(new_pos); // return the new position } github.com - Build software better, together Link to comment Share on other sites More sharing options...
Recommended Posts