My end goal is to use the rotary switch to choose 1 of 4 (or 5 including off) colors. And use the Pot for brightness.
The switch choose red, green, blue or white and off in any of the unused switch settings.
The pot sets the brightness.
Its sort of working.
My problem is the strip sort of blinks. randomly. Maybe call it flickering.
When set to blue I can see the green LED flicker.. When set to green the blue LED flickers. on red theres a flicker of one of the other LEDs as well.
Can somebody check my code and give me some hints on a better way to do this?
Fritzing is also attached to this post.
I havent added the code for white or off yet.
int potPin= A0; //Declare potPin to be analog pin A0
int readValue; // Use this variable to read Potentiometer
int writeValue; // Use this variable for writing to LED
int colorpinvalue; //which switch position was selected
#define REDPIN 5
#define GREENPIN 6
#define BLUEPIN 3
#define BLUEswitch A1
#define REDswitch A2
#define GREENswitch A3
void setup() {
pinMode(potPin, INPUT); //set potPin to be an input
Serial.begin(9600); // turn on Serial Port
pinMode(REDPIN, OUTPUT);
pinMode(GREENPIN, OUTPUT);
pinMode(BLUEPIN, OUTPUT);
}
void loop() {
readValue = analogRead(potPin); //Read the voltage on the Potentiometer
writeValue = (255./1023.) * readValue; //Calculate Write Value for LED
if (analogRead(BLUEswitch) == 1023){
analogWrite(REDPIN, 0); //Write to the LED
analogWrite(GREENPIN, 0); //Write to the LED
analogWrite(BLUEPIN, writeValue); //Write to the LED
}
if (analogRead(GREENswitch) == 1023){
analogWrite(REDPIN, 0); //Write to the LED
analogWrite(GREENPIN, writeValue); //Write to the LED
analogWrite(BLUEPIN, 0); //Write to the LED
}
if (analogRead(REDswitch) == 1023){
analogWrite(REDPIN, writeValue); //Write to the LED
analogWrite(GREENPIN, 0); //Write to the LED
analogWrite(BLUEPIN, 0); //Write to the LED
}
Serial.print("You are writing a value of "); //for debugging print your values
Serial.println(writeValue);
Serial.println(colorpinvalue);
}
Im using these parts:
and Arduino Uno