This has since been solved. TLDR: Cause was dodgy A0 and A1 analog pins. Bought that way.
Hi all,
I recently bought an Uno clone. Works well except for one issue. I'm controlling an rgb strip through mosfets using one potentiometer for each colour. The pwm pins are 9,10,11. No matter what pwm pins i choose, one of them always stays high. In this case, pin 11 lights blue led and its always on fairly dim. I can control the other colours just fine, but blue stays on. My first thought was that pin 11 was borked, so i changed the code to use pin 6 instead. Same issue. I swapped colours around and its not the led strip or the mosfets causing the problem. Its only the third pwm pin, whichever pin it is.
My analog inputs are A0(blue), A1(green), A2(red)
Any ideas?
This is the code:
int writeValue_red; //declare variable to send to the red LED
int writeValue_green; //declare variable to send to the green LED
int writeValue_blue; //declare variable to send to the blue LED
void setup() {
pinMode(potPin_red, INPUT); //set potentiometer for red LED as input
pinMode(potPin_green, INPUT); //set potentiometer for green LED as input
pinMode(potPin_blue, INPUT); //set potentiometer for blue LED as input
pinMode(redPin,OUTPUT); //set pin for red LED as output
pinMode(bluePin,OUTPUT); //set pin for green LED as output
pinMode(greenPin, OUTPUT); //set pin for blue LED as output
}
void loop() {
readValue_red = analogRead(potPin_red); //Read voltage from potentiometer to control red LED
readValue_green = analogRead(potPin_green); //Read voltage from potentiometer to control green LED
readValue_blue = analogRead(potPin_blue); //Read voltage from potentiometer to control blue LED
writeValue_red = (255./1023.)*readValue_red; //Calculate the value to write on the red LED (add point to change to float point)
writeValue_green = (255./1023.)*readValue_green; //Calculate the value to write on the green LED
writeValue_blue = (255./1023.)*readValue_blue; ///Calculate the value to write on the blue LED
analogWrite(redPin,writeValue_red); //write value to set the brightness of the red LED
analogWrite(greenPin,writeValue_green); //write value to set the brightness of the green LED
analogWrite(bluePin,writeValue_blue); //write value to set the brightness of the blue LED
}