Jump to content

I am having a problem that should be super simple, I am sure I am missing something!


G+_Kyle Boyington
 Share

Recommended Posts

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

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

  • 3 weeks later...

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

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

 Share

×
×
  • Create New...