Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is most likely no translated for the post!





Rainbow on a rainbo...
 
Share:
Notifications
Clear all

Rainbow on a rainbow?


(@mr_bridger)
Active Member
Joined: 5 years ago
Posts: 7
Topic starter  

Hi Hans, me again 

Got another question, im not sure if its possible. ive been scratching my head but i dont really get how the "color wheel" works. 

imagine i have a strip of LED's in 4 rows, (not the same length as the arc would make the inside shorter)

for instance, wired like this

Row1                 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15   (outside)

Row2                 29,28,27,26,25,24,23,22,21,20,19,18,17,16

Row3                 30,31,32,33,34,35,36,37,38,39,40,41

Row4                 51,50,49,48,47,46,45,44,43,42      (inside) 

then, i want each whole row to be the same colour, and then graduating to each row through the colour wheel. 

(crudely, Row4 Red, Row3 Orange, Row2 Yellow, Row1 green, THEN Row4 Orange, Row3 Yellow, Row2 Green, Row1 Blue, etc ) 

Do you see where im going with this? i was thinking i could use 4 arrays, eg

int Row1[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};  

or maybe modifying the "SetAll", one for each row like

void Row1(byte red, byte green, byte blue) {
  for(int i = 0; i < 16; i++ ) {
    setPixel(i, red, green, blue);  // Wheel??
  }
}

 

but i cant seem to get my head into how to push the rainbow through the 4 rows. 

Any help would be much appreciated. 

Regards

Ross.


ReplyQuote
 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 1767
 

Hi Ross,

it's been a very busy past 2 days, I'll try to reply tonight ... 


ReplyQuote
 Hans
(@hans)
Noble Member Admin
Joined: 8 years ago
Posts: 1767
 

I just grabbed the rainbow code, for reference:

void loop() {
  rainbowCycle(20);
}
void rainbowCycle(int SpeedDelay) {
  byte *c;
  uint16_t i, j;
  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< NUM_LEDS; i++) {
      c=Wheel(((i * 256 / NUM_LEDS) + j) & 255);
      setPixel(i, *c, *(c+1), *(c+2));
    }
    showStrip();
    delay(SpeedDelay);
  }
}
byte * Wheel(byte WheelPos) {
  static byte c[3];
  
  if(WheelPos < 85) {
   c[0]=WheelPos * 3;
   c[1]=255 - WheelPos * 3;
   c[2]=0;
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   c[0]=255 - WheelPos * 3;
   c[1]=0;
   c[2]=WheelPos * 3;
  } else {
   WheelPos -= 170;
   c[0]=0;
   c[1]=WheelPos * 3;
   c[2]=255 - WheelPos * 3;
  }
  return c;
}

Now, I do not have any hardware near by, but you could try something like this;
First the procedure "rainbowCycle()" sets ever single LED of a strip. "Wheel()" calculates the color depending on where the LED is in the strand.
It uses a "wheel" position - don't ask, I just copied it from AdaFruit - where a wheel is 256 steps. So 256/3 (3 base colors) would result in:

 <85   => Red colors,
<170 => Green colors,
>=170 => Blue colors.

So let's say we want LED's "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15" (your "Row 1") to become red then we'd have to do:

void RowRedForward(int StarLED, int LedsInStripCount) {
  for(int i = 0; i < LedsInStripCount; i++ ) {
      c=Wheel(((i * 256 / LedsInStripCount)) & 255);
      setPixel(StarLED+i, *c, *(c+1), *(c+2));
  }
}

Which would pass "i" (0...16) * 256 and divided by the number of leds in that strip section (16) and "AND" 255.
Just you counting would be different (versus Row1). So for example Row3 has only 12 LEDs, hence the variable "LedsInStripCount".
Since this example is for Red (values <85), but for any starting LED, we need to increase "i" with StartLed to get the right starting point.
Similar for the other rows, where Row2 and Row4 have a backwards loop of course (StartLed-i), something like this;


void RowRedReverse(int StarLED, int LedsInStripCount) {
  for(int i=0; i < LedsInStripCount; i++ ) {
      c=Wheel(((i * 256 / LedsInStripCount)) & 255);
      setPixel(StarLED-i, *c, *(c+1), *(c+2));
  }
}
Now to stick to the colors you want, you'll have to figure out at what "i" the color changes to what you need. I can see that to take some toying around.
Hope this helps getting you started, like I said: I have no hardware at hand right now to test 

ReplyQuote
(@mr_bridger)
Active Member
Joined: 5 years ago
Posts: 7
Topic starter  

Hi Hans,

Many thanks for the reply, its all starting to make my head hurt, lol. 

i cant get my head around the graduations, now thinking about it, as in effect it will only ever show 4 colours. Rows 1,2,3 & 4, so the graduation would need to be bigger. 

for the time being ive added all the LED numbers (191 in total) into a matrix and fill it from the bottom of the legs up to the top in a horizontal manner. to the peak would be red, and the bottom of the legs "violet" or whatever it is, cycling that way.

defining 

int RainMatrix[] ={98,97,71,70,44,43,42,136,45,69,163,72,96,190,0,1,99,18...etc };

and then calling each pixel using RainMatrix in the normal rainbow as below. 

void VerticleRainbow(uint8_t wait) {
  uint16_t i, j;
  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(RainMatrix, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

what i may try later, is defining the base R,O,Y,G,B,I,V  colours per row somehow. and try and cycle them that way without using the wheel like

Row1 - Red

Row1- Orange, Row2 - Red

Row1 - Yellow, Row2 - Orange, Row3 - Red

Row1 - Green, Row2 - Yellow,  Row3 - Orange,  Row4 - Red

Row1 - Blue,   Row2 - Green,   Row3 - Yellow,   Row4 - Orange

Row1 - Indigo, Row2 - Blue,    Row3 - Green ,    Row4 - Yellow

and cycle for X number of times. etc

im sure theres a simple way, but ill have to have a think about that more. [frazzled brain]  

Roaa.


ReplyQuote
(@mr_bridger)
Active Member
Joined: 5 years ago
Posts: 7
Topic starter  

*Ross....

Lol, cant even spell my name 


ReplyQuote



Like what you see and you'd like to help out? 

The best way to help is of course by assisting others with their questions here in the forum, but you can also help us out in other ways:

- Do your shopping at Amazon, it will not cost you anything extra but may generate a small commission for us,
- send a cup of coffee through PayPal ($5, $10, $20, or custom amount),
- become a Patreon,
- donate BitCoin (BTC), or BitCoinCash (BCH).

Share: