Skip to content

Instantly share code, notes, and snippets.

@JarekParal
Last active July 11, 2017 10:25
Show Gist options
  • Save JarekParal/15ad77cb5fc39729b4d7aa6bcb946020 to your computer and use it in GitHub Desktop.
Save JarekParal/15ad77cb5fc39729b4d7aa6bcb946020 to your computer and use it in GitHub Desktop.
analogWrite() on ESP32 - example 1
#include "LearningKit.h"
void setup() {
Serial.begin(115200);
setupRgbLed();
setupLeds();
setupButtons();
ledcSetup(0, 1000, 10); // ledcSetup(channel, freq, resolution)
// channel = 0 - 15
// resolution = 10 => 2^10 => 1024
ledcAttachPin(L_RGB_R, 0); // ledcAttachPin(pin, channel)
}
void loop() {
Serial.println(analogRead(POT1)/4);
ledcWrite(0, analogRead(POT1)/4); // ledcWrite(channel, value)
// value => resolution = 1024 => value = 0 - 1023
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment