Hello all,
I need a little help with my program. I found this code online, modified it a bit, and tried it out using an RGB LED and a single potentiometer (because I only have one on hand):
const int redPin = 9;
const int greenPin = 10;
const int bluePin = 11;
const int redPot = 2;
const int bluePot = 1;
const int greenPot = 3;
int currentRed;
int currentGreen;
int currentBlue;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop(){
currentRed = map(analogRead(redPot), 0, 1024, 0, 255);
currentGreen = map(analogRead(greenPot), 0, 1024, 0, 255);
currentBlue = map(analogRead(bluePot), 0, 1024, 0, 255);
analogWrite(redPin, currentRed);
analogWrite(greenPin, currentGreen);
analogWrite(bluePin, currentBlue);
}
My circuit is:
Common Cathode RGB LED - red anode connected to 220ohm resistor on pin 9, and cathode on +5v.
25ohm potentiometer connected to +5v & GND, with output to analog pin 2.
The problem is that the LED never turns off. It goes from kinda dim when the pot is on the low end, and really bright when the pot is on the high end. I'd like to be able to go from completely off --> fully bright.
Here's a video explaining the situation:
If you have any questions or I wasn't clear, let me know. All help is appreciated!