Apologies if my problem below is obvious but it doesn’t seem obvious to me after reading various websites and even the Arduino example, Stackflow etc to understand what I’m seeing.
I simply implemented a lcd display into the loop code to display (what I thought) would be which led is being controlled. My understanding being that (if) I tested for the logical condition, then (if) true, the code gets executed belonging to the associated (if) statement.
(if) the condition is false, the code is passed over.
So I know from watching the terminal output that the code is working correctly as I see the correct boardpin value being written to the terminal.
What I can’t workout is why lcd displays “GREEN led ON” and “BLUE led ON” when clearly the logical statements are not true because boardpin is neither 10 or 9?
Here are my code warnings:
src\main.cpp: In function 'void loop()':
src\main.cpp:39:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if (boardpin == 11);
^~
src\main.cpp:40:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
{ Serial.println(boardpin, DEC);
^
src\main.cpp:45:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if (boardpin == 10);
^~
src\main.cpp:46:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
{
^
src\main.cpp:52:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if (boardpin == 9);
^~
src\main.cpp:53:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
{
Here is my loop code:
void loop()
{
for (int boardpin = rgb_pins_end; boardpin >= rgb_pins_start; boardpin--)
{
Serial.println(boardpin, DEC);
lcd.begin(16,2);
lcd.setCursor(0,0);
if (boardpin==11);
{ Serial.println(boardpin, DEC);
lcd.setCursor(0,0);
lcd.print("RED led ON");
} delay(delaytime);
if (boardpin ==10);
{
Serial.println(boardpin, DEC);
lcd.setCursor(0,1);
lcd.println("GREEN led ON ");
} delay(delaytime);
if (boardpin ==9);
{
Serial.println(boardpin, DEC);
lcd.setCursor(0,0);
lcd.print("BLUE led ON");
} delay(delaytime);
DimmerFunction_Bright(boardpin);
DimmerFunction_Dim(boardpin);
}
I also tried:
if (boardpin==11);
.
.
.else if (boardpin(==10);
.
.
else if (boardpin==9);
Which throws up 3 problems ‘else’ without a previous ‘if’ [Ln 45, Col5]
Expected a staement
‘else’ without a previous ‘if’
expected a statement…
Rather than a solution can someone explain why, so I can learn from my error of understanding Conditional Statements.
Thank you for your patience, help and guidance with Platformio with a newbie.