Hi, im new to the world of programing and I have some problems with the code for a program.
The project at total is a wake-up lamp with RGB that will dim up the light over a period of time until it is at full brightness when the Arduino Uno gets power.
And I am gonna switch between colors with the help of a switch with 8 on/off.
I use a "for" loop that count up to 255 steps and the brightness depends on how many steps it have made.
So the problem is that when the "for" loop is active I cant interupt it with my switches and I cant turn it off if I turn all switches off.
I would be glad if someone smart person could help me and hopefully I will learn something on the way aswell.
Some spec:
I am gonna use a Arduino UNO with ATMega328P
And the code. Since it is big I will only post the part I think is essential for the problem.
//-----------------------------------Button 2------------------------------------------------------
if (lightMode == 2)
{
if (varRed,varGrn,varBlu <= 255);
{
for (int x=0; x<255; x++) //loop that goes throuh 255 steps.
{
varRed++,varGrn++,varBlu++;
if (varRed,varGrn,varBlu >= 0)
{
delay(dimDelay); //Should be 7000 later for 7sec delay between each fade step at a total of 30 min for full light.
analogWrite(redPin, varRed);
analogWrite(grnPin, varGrn);
analogWrite(bluPin, varBlu);
Serial.print(varRed);
Serial.println(" of 255 fade steps, Red---Button 2");
Serial.print(varGrn);
Serial.println(" of 255 fade steps, Green---Button 2");
Serial.print(varBlu);
Serial.println(" of 255 fade steps, Blue---Button 2");
Serial.print(lightMode);
Serial.println(" lightMode");
if (varRed,varGrn,varBlu >= 255)
{
exit(varRed); //Stops "for" loop so it dosen´t keep counting.
exit(varGrn); //Stops "for" loop so it dosen´t keep counting.
exit(varBlu); //Stops "for" loop so it dosen´t keep counting.
}
}
}
}
}
//------------------------------------Button 2 End------------------------------------------------