Still the same question what were you expecting it to do? A read statement is normally on the other side of a =, setting the variable given before the = to the value that is read.
In fact even analogread A0 is wrong, it should be analogRead(0). The A0 is designed to be used for making digital input / output on an analogue port pin.
However so many people could not wrap their head around that simple concept, they had to change the compile to sort out those using it incorrectly.
Correct, because you never do anything with the result. It is a valid C call which is why you don't get an error, although you might get a warning if you look at all the stuff that is generated during compilation
Yes, but good on you for spotting this and understanding it. A good attitude to take.
But is the code itself good? I included that because the LDR is connected to A0 so I thought it is supposed to be included. What should I do to adjust the RGB LED brightness using the LDR?
Assign the reading from the LDR to a variable, and use the map function to get it into the range 0 to 255. Then use that variable to set one of the components of your RGB colour.
However, if this is a simulator how do you change the light level falling on it. I never use simulators so I don't know.
I figured out a way to change the LEDsbrightness by using a darker shade of red to a lighter shade. But I can't use include other colours and I was supposed to include other colours while varying their brightness.
void setup()
{
pinMode(A0, INPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
}
void loop()
{
if (analogRead(A0) > 100) {
analogWrite(11, 255);
analogWrite(10, 0);
analogWrite(9, 0);
}
if (analogRead(A0) < 800) {
analogWrite(11, 255);
analogWrite(10, 102);
analogWrite(9, 102);
}
if (analogRead(A0) < 900) {
analogWrite(11, 255);
analogWrite(10, 204);
analogWrite(9, 204);
}
delay(10); // Delay a little bit to improve simulation performance
}
Mostly, maybe tuck the delay() into the function and add a parameter for millis so you can have timed color and less typing.
With Arduino, RAM is precious. Make it a habit, use the smallest variable for the job.
Once you do that, it will become automatic.
Type int is 2 bytes, type byte is 1 byte.
Type int counts from -32768 to +32767 and type byte counts from 0 to 255.
What variable type should pin numbers take?
I'd like you to see that this one new-to-you thing shortens the code and practice but while you're at it, every time the code grows -- there might be a thing that will save all that work that your time is better spent finding than pushing along the hard way.