I posted about this already but have not received any help for it. Maybe its because last post i really did not know what i was doing, but its all becoming more clear. could someone give me some advice/ show me something to read that will help me come up with the solution.
I want a pot to read its value and write the speed at which the LEDs fade together. Im positive this can be done.
the code below includes what im at with a very important part of this. also it include a direction i think it would need to go to get this working. im just going to keep plugging away over here so i would really appreciate some help. thanks fellow arduino people.
int calculateStep(int prevValue, int endValue)
{
int step = endValue - prevValue;
if (step)
{
step = 1020/step;
}
return step;
}
int calculateVal(int step, int val, int i)
{
if ((step) && i % step == 0)
{
if (step > 0)
{
val += 1;
}
else if (step < 0)
{
val -= 1;
}
}
//calculate step/val is the math for what controls the fade function
if (val > 255)
{
val = 255;
}
if (val < 0)
{
val = 0;
}
return val;
}
void crossFade(int color[3])
// this says that 'crossFade' controls 3 intigers and gives them the names R,G,B
{
int R = color[0];
int G = color[1];
int B = color[2];
int stepR = calculateStep(prevR, R);
int stepG = calculateStep(prevG, G);
int stepB = calculateStep(prevB, B);
//when the loop starts over it says to move from last color value to new through the math equation
//which is said at the bottom of the code for the loop
for (int i = 0; i <= 1020; i++)
// im not too sure about this.. it says value = 0 and value is less than or equal too 1020
// and increase value
{
redVal = calculateVal(stepR, redVal, i);
grnVal = calculateVal(stepG, grnVal, i);
bluVal = calculateVal(stepB, bluVal, i);
// rbgVal is the calculated of fade from last value to new value, ???, and the value...
analogWrite(redPin, redVal);
analogWrite(grnPin, grnVal);
analogWrite(bluPin, bluVal);
// tell the pins to do this
delay(fade);
// slow this process down what ever number was given to 'fade'
// ??delay(analogRead(sensorPin));?? maybe starting off with something like this? instead of delay(fade)
{
if (DEBUG)
{
if (i == 0 or i % loopCount == 0)
{
Serial.print("loop/RGB: #");
Serial.print(i);
Serial.print(" | ");
Serial.print(redVal);
Serial.print(" / ");
Serial.print(grnVal);
Serial.print(" / ");
Serial.print(bluVal);
}
DEBUG += 1;
}
}
prevR = redVal;
prevG = grnVal;
prevB = bluVal;
delay(hold);
}
Moderator edit: code tags added.