Hardwarenahe Programmierung

You are viewing an older revision! See the latest version

PWM LED

Öffnen Sie Ihre Arduino IDE und kopieren Sie den folgenden Code.

mbed_ESP32_PWM_LED1

const int LED1 = 19;  

// setting PWM properties
const int freq = 5000;
const int ledChannel = 0;
const int resolution = 8;
 
void setup(){
  // configure LED PWM functionalitites
  ledcSetup(ledChannel, freq, resolution);
  
  // attach the channel to the GPIO to be controlled
  ledcAttachPin(LED1, ledChannel);
}
 
void loop(){
  // increase the LED brightness
  for(int dutyCycle = 0; dutyCycle <= 255; dutyCycle++){   
    // changing the LED brightness with PWM
    ledcWrite(ledChannel, dutyCycle);
    delay(15);
  }

  // decrease the LED brightness
  for(int dutyCycle = 255; dutyCycle >= 0; dutyCycle--){
    // changing the LED brightness with PWM
    ledcWrite(ledChannel, dutyCycle);   
    delay(15);
  }
}

Aufgabe

Schreibe das mbed Demo-Programm app-board-RGB für den ESP32 um (siehe auch https://os.mbed.com/users/fpucher/code/ESP32/wiki/RGB-Led|RGB-Led]].


All wikipages