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!

Moderator: phalanx

Post Reply
svenkranz
Posts: 1
Joined: Wed Apr 25, 2018 7:45 am

multiple LEDs sinus wave with different peak intensities

Post by svenkranz » Wed Apr 25, 2018 7:56 am

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;
int fadeAmount=255;
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;

}
}

Post Reply