I did it this way but k doesn't change
//https://www.i-programmer.info/programming/148-hardware/17804-programming-the-esp32-in-c-pwm-first-example.html?start=4#google_vignette
#include <driver/ledc.h>
int k;
//+++++++++++++++++++++++++++++++
void frequencyChange() //void somefunc()
// your variable here
{
if (digitalRead(16) == LOW) {
k++;
}
if (digitalRead(17) == LOW) {
k--;
}
//++++++++++++++ // put your setup code here, to run once:+++++++++++++++
ledc_timer_config_t timerConfig = {
.speed_mode = LEDC_LOW_SPEED_MODE,
.duty_resolution = LEDC_TIMER_10_BIT,
.timer_num = LEDC_TIMER_0,
.freq_hz = k, //+++++++++++++++++++++++++++++
.clk_cfg = LEDC_AUTO_CLK
};
ledc_timer_config(&timerConfig);
Serial.println(k);
Serial.println(" k1 ");
//+++++++++++++++++++++++++++++
}
//+++++++++++++++++++++++++++++++++
void setup() {
Serial.begin(115200);
pinMode(16, INPUT_PULLUP); //k++
pinMode(17, INPUT_PULLUP); //k--
/*
ledc_timer_config_t timerConfig = {
.speed_mode = LEDC_LOW_SPEED_MODE,
.duty_resolution = LEDC_TIMER_10_BIT,
.timer_num = LEDC_TIMER_0,
.freq_hz = 10000, //+++++++++++++++++++++++++++++
.clk_cfg = LEDC_AUTO_CLK
};
ledc_timer_config(&timerConfig);
*/
ledc_channel_config_t channelConfig1 = {
.gpio_num = 18,
.speed_mode = LEDC_LOW_SPEED_MODE,
.channel = LEDC_CHANNEL_0,
.timer_sel = LEDC_TIMER_0,
.duty = 512,
.hpoint = 0
};
ledc_channel_config(&channelConfig1);
ledc_channel_config_t channelConfig2 = {
.gpio_num = 19,
.speed_mode = LEDC_LOW_SPEED_MODE,
.channel = LEDC_CHANNEL_1,
.timer_sel = LEDC_TIMER_0,
.duty = 512,
.hpoint = 256
};
ledc_channel_config(&channelConfig2);
}
void loop()
{
Serial.println(k);
Serial.println(" k2 ");
delay( 100 );
}