Hello!
For my pet project I need enable PWM with 1.5MHz and read result with analogRead(pin_number);
The problem is: PWM is working only with build-in LED (Green and Blue on evaluation board).
Basically now, I am trying replicate following small project for ESP32 ESP32 PWM with Arduino IDE (Analog Output) | Random Nerd Tutorials with no luck so far.
Any ideas why tone function is working only for internal LEDs and how to fix it? Thanks!
Code:
uint8_t ledPin = PA1; // BLUE LED - working
//uint8_t ledPin = PA0; // GREEN LED - working
//uint8_t ledPin = PA8; //IO2 - not working
//uint8_t ledPin = PB5; //IO1 - not working
int freq = 5000;
void setup()
{
Serial.begin(115200);
delay(2000);
pinMode(ledPin, OUTPUT);
tone(ledPin, freq);
}
void loop()
{
for(int dutyCycle = 0; dutyCycle <= 255; dutyCycle++){
// changing the LED brightness with PWM
analogWrite(ledPin, dutyCycle);
delay(15);
}
// decrease the LED brightness
for(int dutyCycle = 255; dutyCycle >= 0; dutyCycle--){
// changing the LED brightness with PWM
analogWrite(ledPin, dutyCycle);
delay(15);
}
}