Problems PWM Crossfading 2 LEDs


#1

I’m trying to crossfade two LEDs by analog reading the value from 2 pots and PWMing to control LED brightness. One pot controls overall brightness, and the other pot makes the LEDs brightness vary to control total color. I’m programming using the Arduino IDE, and the sketch below works on my Uno, but when I switch to the Nano v2 I have problems.

I think the issue is related to the ADC input range, or the PWM output range being different between the Uno and Nano. Looking through the data sheets, it looks like the Nano ADC is 12-bit (0-4095), but changing from the 10-bit (0-1023) value I have in the code doesn’t help.

Anyone have any ideas?

//Pin assignment variables
const int brightness_pot = A4;   //pot connected to analog read 4 (A4), for dimming both LEDs
const int color_pot = A5;         //pot connected to analog read 5 (A5), for dimming changing color temp
const int warm_output = D1;      //pin (D1) connected to gate on MOSFET controlling warm LED
const int cool_output = D0;      //pin (D0) connected to gate on MOSFET controlling color LED
const int ledPin = 13;        //built in LED (D13)

//LED Blink Time variables:
unsigned long previousMillis =0;
int ledState = LOW;

void setup() {
  
pinMode(warm_output, OUTPUT); //define output pins
pinMode(cool_output, OUTPUT);
pinMode(ledPin, OUTPUT);
}

void loop() {
  
//Make onboard LED Blink
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= 250) {
    previousMillis = currentMillis;
    if(ledState==LOW){
      ledState=HIGH;
    } else {
      ledState=LOW;
    }
    digitalWrite(ledPin, ledState);
  }

//Read Analog inputs and crossfade LEDs
  int brightness = map(analogRead(brightness_pot),0,1023,0,255);
  int pWarm = map(analogRead(color_pot),0,1023,0,brightness);
  int pCool = map(analogRead(brightness_pot),0,1023,brightness,0);
  analogWrite(warm_output,pWarm);
  analogWrite(cool_output,pCool);
}

#2

hi typekg,
the default ADC of Nano2 is 10bits refer to wiring_analog and you can call analogReadResolution() to modify resolution. In addition, you can use A0,A1,A2,A3 with PWM utility to try to verify