const int PWM_CHANNEL = 0; // ESP32 has 16 channels which can generate 16 independent waveforms
const int PWM_FREQ = 500; // Recall that Arduino Uno is ~490 Hz. Official ESP32 example uses 5,000Hz
const int PWM_RESOLUTION = 10; // We'll use same resolution as Uno (8 bits, 0-255) but ESP32 can go up to 16 bits
const int LED_OUTPUT_PIN = 18;
const int PWM_CHANNEL2 = 0; // ESP32 has 16 channels which can generate 16 independent waveforms
const int PWM_FREQ2 = 500; // Recall that Arduino Uno is ~490 Hz. Official ESP32 example uses 5,000Hz
const int PWM_RESOLUTION2 = 10; // We'll use same resolution as Uno (8 bits, 0-255) but ESP32 can go up to 16 bits
const int LED_OUTPUT_PIN2 = 26;
const int PWM_CHANNEL3 = 0; // ESP32 has 16 channels which can generate 16 independent waveforms
const int PWM_FREQ3 = 500; // Recall that Arduino Uno is ~490 Hz. Official ESP32 example uses 5,000Hz
const int PWM_RESOLUTION3 = 10; // We'll use same resolution as Uno (8 bits, 0-255) but ESP32 can go up to 16 bits
const int LED_OUTPUT_PIN3 = 27;
// The max duty cycle value based on PWM resolution (will be 255 if resolution is 8 bits)
const int MAX_DUTY_CYCLE = (int)(pow(2, PWM_RESOLUTION) - 1);
const int DELAY_MS = 100; // delay between fade increments
bool first=1; //Nach erstem Durchlauf. Danach auf 0 setzen
void setup() {
Serial.begin(9600);
// Sets up a channel (0-15), a PWM duty cycle frequency, and a PWM resolution (1 - 16 bits)
// ledcSetup(uint8_t channel, double freq, uint8_t resolution_bits);
//ledcSetup(PWM_CHANNEL, PWM_FREQ, PWM_RESOLUTION);
// bool ledcAttach(uint8_t pin, uint32_t freq, uint8_t resolution);
ledcAttach(LED_OUTPUT_PIN, PWM_FREQ, PWM_RESOLUTION);
ledcAttach(LED_OUTPUT_PIN2, PWM_FREQ2, PWM_RESOLUTION2);
ledcAttach(LED_OUTPUT_PIN3, PWM_FREQ3, PWM_RESOLUTION3);
// ledcAttachPin(uint8_t pin, uint8_t channel);
//ledcAttachPin(LED_OUTPUT_PIN, PWM_CHANNEL);
}
void loop() {
/* // fade up PWM on given channel
for(int dutyCycle = 0; dutyCycle <= MAX_DUTY_CYCLE; dutyCycle++){
ledcWrite(LED_OUTPUT_PIN, dutyCycle);
ledcWrite(LED_OUTPUT_PIN2, dutyCycle);
ledcWrite(LED_OUTPUT_PIN3, dutyCycle);
Serial.println(LED_OUTPUT_PIN);
Serial.println(dutyCycle);
Serial.println(ledcRead(LED_OUTPUT_PIN));
delay(DELAY_MS);
}
// fade down PWM on given channel
for(int dutyCycle = MAX_DUTY_CYCLE; dutyCycle >= 0; dutyCycle--){
ledcWrite(LED_OUTPUT_PIN, dutyCycle);
ledcWrite(LED_OUTPUT_PIN2, dutyCycle);
ledcWrite(LED_OUTPUT_PIN3, dutyCycle);
Serial.println(LED_OUTPUT_PIN);
Serial.println(dutyCycle);
Serial.println(ledcRead(LED_OUTPUT_PIN));
delay(DELAY_MS);
}
*/
if(first == 1){
Serial.println(first);
ledcWrite(LED_OUTPUT_PIN, 500);
ledcWrite(LED_OUTPUT_PIN2, 500);
ledcWrite(LED_OUTPUT_PIN3, 500);
first=0;
Serial.println(first);
}
//bool ledcFade(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms);
for (int i=0; i <= 1023; i=((i+(i*0.1)+1))){
Serial.println(i);
ledcWrite(LED_OUTPUT_PIN, i);
delay(DELAY_MS);
}
ledcWrite(LED_OUTPUT_PIN, 1023);
delay(500);
for (int i=1023; i >= 0; i=((i-(i*0.1)-1))){
Serial.println(i);
ledcWrite(LED_OUTPUT_PIN, i);
delay(DELAY_MS);
}
ledcWrite(LED_OUTPUT_PIN, 0);
Serial.println("Nach If, Vor Fade");
//Serial.println(ledcFade(LED_OUTPUT_PIN, 500, 0, 20));
Serial.println("Feda 500-0");
delay(500);
//ledcFade(LED_OUTPUT_PIN, 0, 1023, 2000);
Serial.println("Feda 0-1023");
delay(500);
}