# SparkFun Forums

### multiple LEDs sinus wave with different peak intensities

General project discussion / help
Did you make a robotic coffee pot which implements HTCPCP and decafs unauthorized users? Show it off here!

### multiple LEDs sinus wave with different peak intensities#199062

By svenkranz
#199062
Hi community,

I try to create an LED pattern which allows me to drive my LED intensity using a sinus curve with non repetitive max and min. I basically want to start the LED intensity at 5, ramp it up to 30, down to 20, up to 100, down to 50). I need this for multiple LED colors, each controlled separately. At the moment I ramp it up in a linear fashion but have not been able to figure out how to do this in a sinus fashion. I am relatively new to the micro-contoller world- so the code shown below (linear pattern might be inefficient - but it worked for the linear ramping).

(Arduino mega with pico buck LED driver and CREE high power LEDs.)

int value_2[14] = {10,100, 50, 200, 70, 255, 70, 200, 50, 100, 10, 10, 5};// blue LED
int value_3[14] = {10,40, 20, 100, 50, 200, 50, 100, 20, 40, 5, 5, 2}; //green LED

int step;
void setup()
{
step = 0;
Serial.begin(9600);
pinMode(2, INPUT);
pinMode(3, INPUT);
}

void loop()
{

// linear scaling that ramps to zero over 256 subdivisions
// the next point
// linear scaling that ramps to one.

byte brightness_2 =
value_2[(step/256)%14] * // the current point for the next 256 subdivisions
(1.0 - (step%256/256.0)) + // linear scaling that ramps to zero over 256 subdivisions
value_2[(step/256+1)%14] * // the next point
(step%256/256.0); // linear scaling that ramps to one.

byte brightness_3 =
value_3[(step/256)%14] * // the current point for the next 256 subdivisions
(1.0 - (step%256/256.0)) + // linear scaling that ramps to zero over 256 subdivisions
value_3[(step/256+1)%14] * // the next point
(step%256/256.0); // linear scaling that ramps to one.

//byte brightness_13 =
// value_13[(step/256)%14] * // the current point for the next 256 subdivisions
// (1.0 - (step%256/256.0)) + // linear scaling that ramps to zero over 256 subdivisions
// value_13[(step/256+1)%14] * // the next point
// (step%256/256.0); // linear scaling that ramps to one.

analogWrite(2,brightness_2);
analogWrite(3,brightness_3);

delay(10); / time intervals for the ramping
step++;

if (step > 14*256) {
step = 0;

}
}
###### long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

###### Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

###### Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

###### Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]