Skip to content

Instantly share code, notes, and snippets.

@kakopappa
Created September 27, 2023 09:25
Show Gist options
  • Save kakopappa/b34693c62c679437fa3a7465a242d7f2 to your computer and use it in GitHub Desktop.
Save kakopappa/b34693c62c679437fa3a7465a242d7f2 to your computer and use it in GitHub Desktop.
const int pwmPin = 16; // 16 corresponds to GPIO16 of ESP32
// setting PWM properties
const int freq = 1000; // 1KHz
const int ledChannel = 0;
const int resolution = 8;
void setup(){
ledcSetup(ledChannel, freq, resolution);
ledcAttachPin(pwmPin, ledChannel);
}
void loop(){
/* dutyCycle between 0 to 115 does not seems to have an any effect on the bulb. */
// increase the brightness.
for(int dutyCycle = 115; dutyCycle <= 255; dutyCycle++){
ledcWrite(ledChannel, dutyCycle);
delay(15);
}
// decrease the brightness
for(int dutyCycle = 255; dutyCycle >= 115; dutyCycle--){
ledcWrite(ledChannel, dutyCycle);
delay(15);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment