Skip to content

Commit

Permalink
Merge pull request schmurtzm#16 from 0neday/patch-1
Browse files Browse the repository at this point in the history
Update main.cpp , fix analogWrite for LED on esp32
  • Loading branch information
schmurtzm authored Apr 18, 2022
2 parents e054732 + b190e43 commit af1fdd6
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ boolean willRetain = false;
byte willQoS = 0;

int counter = 0;

// setting PWM properties
const int freq = 5000;
const int ledChannel = 0;
const int resolution = 8;


// AudioRelated ---------------------------

// ============== declarations for buttons : ==============
Expand Down Expand Up @@ -319,7 +326,7 @@ iotwebconf::SelectParameter samVoice = IotWebConfSelectParameter("samVoice", "sa
iotwebconf::TextParameter GoogleTTSvoiceParam = iotwebconf::TextParameter("Google TTS Voice code (<a href=""https://github.com/florabtw/google-translate-tts/blob/master/src/voices.js"" target=""_blank"">list</a>)", "GoogleTTSvoice", GoogleTTSvoice, sizeof(GoogleTTSvoice));


//#define LED_Pin 5 // external LED pin
#define LED_Pin 2 // external LED pin

char *mqttFullTopic(const char action[])
{
Expand Down Expand Up @@ -351,8 +358,13 @@ void broadcastStatus(const char topic[], String msg)
void updateLEDBrightness(int brightness_percentage)
{
#ifdef LED_Pin
#ifdef ESP32
ledcWrite(ledChannel, (int)brightness_percentage * 255 / 100);
#else
analogWrite(LED_Pin, (int)brightness_percentage * 255 / 100);
#endif

#endif
}

void mqttReconnect()
Expand Down Expand Up @@ -1039,6 +1051,8 @@ void setup()
#endif

#ifdef LED_Pin
ledcSetup(ledChannel, freq, resolution);
ledcAttachPin(LED_Pin, ledChannel);
pinMode(LED_Pin, OUTPUT);
updateLEDBrightness(10);
#endif
Expand Down

0 comments on commit af1fdd6

Please sign in to comment.