I´m new in ESP and I need to control duty of PWM by analogue signal connected to the internal ADC. I have this code:
Code: Select all
const int analogInputPin = 36;
const int pwmOutputPin = 2;
void setup() {
pinMode(analogInputPin, INPUT);
ledcSetup(0, 78000, 10); // freq of PWM 78kHz, 10bit
ledcAttachPin(pwmOutputPin, 0);
}
void loop() {
int analogValue = analogRead(analogInputPin);
ledcWrite(0, analogValue);
}
Thanks!