/*
// Potentiometer is connected to GPIO 34 (Analog ADC1_CH6)
const int potPin = 34;
// variable for storing the potentiometer value
int potValue = 0;
void setup() {
Serial.begin(115200);
delay(1000);
}
void loop() {
// Reading potentiometer value
potValue = analogRead(potPin);
Serial.println(potValue);
delay(500);
}
*/
const int potPin = 34; //GPIO 15 entrada potenciometro
const int outPWM = 23; //GPIO 23 saída PWM
const int enOut = 21; //GPIO 21 habilita saída PWM
int potValue = 0; //Variavel para armazenar o valor do potenciometro
//Propriedades do PWM
const int frequencia = 5000; //5KHz
const int Channel = 0; //Canal
const int resolucao = 8; //8 bits
void setup() {
Serial.begin(115200);
pinMode(enOut, OUTPUT);
ledcSetup(Channel, frequencia, resolucao); //Configuração do PWM
ledcAttachPin(outPWM, Channel); //Configuração do pino
delay(1000);
}
void loop() {
potValue = analogRead(potPin);
Serial.println(potValue);
int dutyCycle = (potValue/16); //Transforma 12 bits em 8 bits / relação de entrada 4096 para saída 256
ledcWrite(Channel, dutyCycle);
Serial.println(dutyCycle);
}