Code: Select all
int consignePin = 25;
int controlePin = 36;
int ledPin = 5;
int freq = 5000;
int ledChannel = 0;
int resolution = 8;
void setup() {
// put your setup code here, to run once:
pinMode(ledPin,OUTPUT);
pinMode(consignePin,OUTPUT);
pinMode(controlePin,INPUT);
Serial.begin(9600);
ledcSetup(ledChannel, freq, resolution);
ledcAttachPin(consignePin, ledChannel);
}
void loop() {
for (int dutyCycle = 0; dutyCycle <= 255; dutyCycle++) {
ledcWrite(ledChannel, dutyCycle);
analogReadResolution(10);
Serial.println(int(analogRead(controlePin)));
delay(100);
}
for (int dutyCycle = 255; dutyCycle >= 0; dutyCycle--) {
ledcWrite(ledChannel, dutyCycle);
analogReadResolution(10);
Serial.println(int(analogRead(controlePin)));
delay(100);
}
}
Here is my problem : on the serial monitor, I get complete incoherent values, like 0 when dutyCycle = 0 and 917 for all other values.
I also tried analogReadResolution 8,11 and 12 but I got the same kind of problem.
I tried to read with that too :
//adc1_config_width(ADC_WIDTH_BIT_12);
//adc1_config_channel_atten(ADC1_CHANNEL_0,ADC_ATTEN_DB_0);
//int val = adc1_get_raw(ADC1_CHANNEL_0);
but it didn't work either !
I mesured the voltage with a multimeter, and it works perfectly, so it's not a writting problem.
Do you see a solution to my problem ?