Go Down

Topic: RGB LEDs won't Light up Properly (Read 339 times) previous topic - next topic

tatekolton

Hi All,

I am trying to program 2 RGB LEDs so that they light up different colours depending on a potentiometer reading. I have created arrays for each of the 6 cases but when I upload the code, one LED shines red and the other shines green no matter where I turn the Potentiometer. I tried printing the pot output to verify that the values are between 0 and 60 and they are. Can anyone spot my error? Thanks for the help!

PaulRB

Can you post your code in code tags please. Can't open .ino files on my tablet. Also post your schematic so we can check the wiring and see what type of Arduino and leds you are using. The forum guide in the sticky post will explain how, pleaset read the whole guide.

Grumpy_Mike

#2
Aug 25, 2020, 11:52 am Last Edit: Aug 25, 2020, 11:53 am by Grumpy_Mike
Code: [Select]
if (10<=lightVal<20)
This is not how the C language works. You have to use:-
Code: [Select]
if (10 <= lightVal && lightVal <20)

Or more conventionally
Code: [Select]
if (lightVal >=10  && lightVal <20)

The && means the logical "and" operator.


Go Up