hello every i am trying to make first led goes to full brightness using potentiometer while the other led goes from full brightness to full darkness.
help please
What difficulty are you actually having?
Are the LEDs the correct way around?
yes sir the connection is correct but the problem with coding to control brightness of leds
such that one LED brightness increases with increasing potentiometer voltage, while the other LED brightness decreases with increasing potentiometer voltage
Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project
See About the Installation & Troubleshooting category.
The sketch is declaring global variables as follows:
int x=11;
int z=9;
It is then trying to re-declare these same variables in void loop():
int x=map(r,0,1023,0,255);
int z=map(r,1023,0,255,0);
That's going to throw an error. It is then incorrectly trying to assign these re-declared values to pins 11 and 9. The second statement will return exactly the same result as the first. Have a think about why, as well as what you need to change in it so that it returns an inverse value. In fact, you can also get an inverse value without using a second map statement.
At the start of the sketch, variables x and z hold the pin numbers. The sketch does not then want to be re-declaring these variables to be something else. In fact, since they don't change, they should probably be declared as const:
const int x = 11;
const int z = 9;
You might also want to give them meaningful names instead of x and z:
const int redLed = 11;
const int greenLed = 9;
That way, you won't forget what they are being used for.
New variables are then required to hold the mapped value of r within the loop:
int val1 = map(r,0,1023,0,255);
You then set the pins designated by the values of x and z to the resulting PWM value accordingly:
analogWrite(redLed, val1);
I will let you figure out the other one.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
