Hello, I apologize in advance as I know this is already covered in different posts but I am having trouble understanding how to do this for my application.
I am creating a 24v CCT LED dimmer, one potentiometer controls brightness and one controls the balance of warm to cool light. The code works fine but I want to increase the PWM frequency to reduce flicker in images and videos. I think I need it above 1khz.
What would I add to my code to make this modification to the standard frequency of the controller? I know that different pins use different timers, I am open to switching to different pins if needed. Thanks for the help!
// Pin Definitions
const int brightnessPotPin = A0; // Potentiometer for overall brightness
const int balancePotPin = A1; // Potentiometer for warm/cool balance
const int warmLEDPin = 3; // PWM output pin for warm LEDs
const int coolLEDPin = 5; // PWM output pin for cool LEDs
void setup() {
// Set LED pins as outputs
pinMode(warmLEDPin, OUTPUT);
pinMode(coolLEDPin, OUTPUT);
}
void loop() {
// Read the overall brightness potentiometer (0 to 1023)
int brightnessValue = analogRead(brightnessPotPin);
// Map the brightness value to the PWM range (0 to 255)
int brightnessPWM = map(brightnessValue, 0, 1023, 0, 255);
// Read the warm/cool balance potentiometer (0 to 1023)
int balanceValue = analogRead(balancePotPin);
// Map the balance value to percentages for warm and cool LEDs
int warmRatio = map(balanceValue, 0, 1023, 255, 0); // Warm proportion
int coolRatio = map(balanceValue, 0, 1023, 0, 255); // Cool proportion
// Scale the brightness for warm and cool LEDs
int warmPWM = (brightnessPWM * warmRatio) / 255; // Brightness scaled by warm proportion
int coolPWM = (brightnessPWM * coolRatio) / 255; // Brightness scaled by cool proportion
// Set the PWM output for warm and cool LEDs
analogWrite(warmLEDPin, warmPWM);
analogWrite(coolLEDPin, coolPWM);
}