/*******************************************************************
ESP32 PWM with Arduino IDE (Analog Output)
Quelle: https://randomnerdtutorials.com/esp32-pwm-arduino-ide/
Beispiel: https://raw.githubusercontent.com/RuiSantosdotme/ESP32-Course/master/code/LED_PWM_Example_1/LED_PWM_Example_1.ino
modifiziert
******************************************************************/
// PWM pins
const int ledPin1 = 13; // 16 corresponds to GPIO16
const int ledPin2 = 12;
const int ledPin3 = 14;
// setting PWM properties
const int freq = 1000;
const int ledChannel = 0;
const int resolution = 8;
void setup(){
// configure LED PWM functionalitites
ledcSetup(ledChannel, freq, resolution);
// attach the channel to the GPIO's to be controlled
ledcAttachPin(ledPin1, ledChannel);
ledcAttachPin(ledPin2, ledChannel);
ledcAttachPin(ledPin3, ledChannel);
}
void loop(){
// increase the LED brightness
for(int dutyCycle = 0; dutyCycle <= 255; dutyCycle+=16){
ledcWrite(ledChannel, dutyCycle); // changing the LED brightness with PWM
delay(250);
}
// decrease the LED brightness
for(int dutyCycle = 255; dutyCycle >= 0; dutyCycle-=16){
ledcWrite(ledChannel, dutyCycle); // changing the LED brightness with PWM
delay(250);
}
}