Skip to content

Instantly share code, notes, and snippets.

@JarekParal
Created July 11, 2017 10:23
Show Gist options
  • Save JarekParal/ec3a86dca12cf6eee2f95f8b9763e2af to your computer and use it in GitHub Desktop.
Save JarekParal/ec3a86dca12cf6eee2f95f8b9763e2af to your computer and use it in GitHub Desktop.
analogWrite() on ESP32 - example 2
#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)
ledcSetup(1, 1000, 10);
ledcAttachPin(L_G, 1);
}
void loop() {
Serial.print(analogRead(POT1)/4);
ledcWrite(0, analogRead(POT1)/4); // ledcWrite(channel, value)
// value => resolution = 1024 => value = 0 - 1023
Serial.print(" ");
Serial.println(analogRead(PHOTO)/4);
ledcWrite(1, analogRead(PHOTO)/4);
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment