ropg / heltec_esp32_lora_v3

Proper working Arduino library for the Heltec ESP32 LoRa v3 board, as well as for Wireless Stick v3 and Wireless Stick Lite v3. Uses RadioLib
MIT License
373 stars 22 forks source link

Update heltec.h #10

Closed Evs91 closed 6 months ago

Evs91 commented 7 months ago

Updated LED Control to new API with ledcAttach, ledcWrite, ledcDetach.

https://espressif-docs.readthedocs-hosted.com/projects/arduino-esp32/en/latest/migration_guides/2.x_to_3.0.html

ropg commented 7 months ago

Strangely enough, I have ESP32 2.0.15 installed, but when I try to call ledcAttach and ledcDetach, I get errors. It works with the old ledcAttachPin and ledcDetachPin.

image
Evs91 commented 7 months ago

Ahh - well I guess we can call it a "pre-release bug fix?" I'm on the 3.0.0 release since I needed the compatibility with the new C6 and H2 boards. image

ropg commented 6 months ago

If you figure out what #defines are set for 3 vs 2, we can #ifdef the old and the new...

ropg commented 6 months ago

The version on GitHub now has the following for heltec_led, so it should work on both 2.x and 3.0. Please test if this works for you also.

void heltec_led(int percent) {
  if (percent > 0) {
    #if ESP_ARDUINO_VERSION_MAJOR == 3
      ledcAttach(LED_PIN, LED_FREQ, LED_RES);
    #else
      ledcSetup(LED_CHAN, LED_FREQ, LED_RES);
      ledcAttachPin(LED_PIN, LED_CHAN);
    #endif
    ledcWrite(LED_CHAN, percent * 255 / 100);
  } else {
    #if ESP_ARDUINO_VERSION_MAJOR == 3
      ledcDetach(LED_PIN);
    #else
      ledcDetachPin(LED_PIN);
    #endif
    pinMode(LED_PIN, INPUT);
  }
}
ropg commented 6 months ago

I've changed the ==3 to >=3 and added this to the new release that just went live.