Hey guys,
First of all, I want to say that I appreciate for taking from your personal time to answer to my question. Anyway here's the issue.
I want to a fade the led brightness to a set value without delay. This is code:
**'dim' is the actual led brightness
**'set_value ' is the brightness level set through serial
PS: The serial function has been omitted intentionally.
//////////////////////////
int fadeAmount = 1; // how many points to fade the LED by
unsigned long currentTime;
unsigned long loopTime;
int set_value = 115; // the brightness level set from serial
int dim = 0;
void setup()
{
currentTime = millis();
loopTime = currentTime;
}
void loop()
{
currentTime = millis();
if(currentTime >= (loopTime + 50))
{
if(set_value < dim)
{
fadeAmount = -fadeAmount;
dim+=fadeAmount;
}
if(set_value > dim)
{
fadeAmount = 1;
dim+=fadeAmount;
}
loopTime = currentTime; // Updates loopTime
}
}
/////////////////////////
What am I doing wrong? ![]()