Go Down

Topic: Bandwidth Meter (Read 1 time) previous topic - next topic

jonathansm

I have an Arduino Uno and I'm using the NeoPixel strip. I'm creating a bandwidth meter. What I'm having issues with is calculating what color to use. What I want to do it have the strip gradient from green->yellow->red. To determine how many LEDs to fill I just calculate the percent of bandwidth then calculate the percentage of how many LEDs are in the strip. For example if I have a max bandwidth of 1Gbit/s and I am using 250Mbit/s that would be about 15 leds lit and mostly green The thing I'm having issues with is calculating the color. Any help would be great.

arduinodlb

I assume you have worked out a way to determine your bandwidth and the question you are asking is how to turn that value into the colors you want on the LEDs.

If that is the case, then assuming you get a value back from your bandwidth used algorithm between 0 and 255 (8-bit precision)...

I haven't tried this, but my thoughts are this:

Your values are RGB.
Green = 0,255,0
Yellow = 255,255,0
Red = 255,0,0

So, your calculated RGB values for 8-bit source precision are:
0 = 0,255,0
128 = 255,255,0
255 = 255,0,0

So, for source values 0-127, set RGB as (value * 2, 255, 0)
For source values 127-255, set RGB as ((value*2)-255), (255-value)*2, 0)
Do not IM me. I will not respond. Ask questions in the forum.

jonathansm

Sorry I'll be a little more clear. What my question is how can I have a gradient of green at one end yellow in the middle and red at the end. Like if my bandwidth was 250Mbits it would be mostly green and maybe a little yellow, but If the bandwidth was 750Mbits the strip would be green at the beginning and gradient to yellow and maybe a little red at the end. Hopefully that makes sense.

Magician

Create a look-up-table, where you would keep a color of each led, for example:
Code: [Select]
const     uint8_t   mix_coef1[3][8][3]  = {
{{255,  0,  0},{255,  0,  0},{255,255,127},{255,255,255},\
{255,255,255},{255,255,255},{255,255,255},{255,255,  0}},\ 
{{255,255,  0},{255,255,  0},{255,255,  0},{255,255,  0},\
{255,255,  0},{255,255,  0},{255,255,  0},{255,255,  0}},\ 
{{  0,  0,255},{  0,  0,255},{255,255,  0},{255,255,  0},\
{255,255,  0},{255,255,  0},{255,255,  0},{255,255,  0}}    //Primary Colors Plate
};
I used 3D array, but you may be o'k with 2D, mix_coef[N][3], where N - number of leds.
http://coolarduino.wordpress.com/2012/07/01/audio-vu-meter-ac-micro-voltmeter-with-extra-wide-dynamic-range-72-db/

Grumpy_Mike

Quote
Sorry I'll be a little more clear. What my question is how can I have a gradient of green at one end yellow in the middle and red at the end.

Sorry but not clear at all.
If the length of the illuminated strip is changing that is one problem and can be solved by a static look up table. However if all the LEDs in the strip are on and you just want to change the colour spread then you will have to take another approach.

Think of colour as just a 3 coordinate system. To go from green ( R=0, G=full, B=0 ) to yellow ( R=full, G=full, B=0 ) in a fixed number of steps say S, then the change in Red goes from 0 to full in S steps, so the red component of each LED changes by :-
full - 0 / S
you do the same for each component of the colour.

So in your code you would pick how many LEDs you want the yellow point and calculate the LED's colour to that point. Then do the same from the yellow to the red point. If you make the red point a value greater than the number of LEDs you actually have you will not always get any red LEDs.

So your data, in your case the bandwidth will be represented by simply two numbers, the yellow point and the red point.

Go Up