-
Notifications
You must be signed in to change notification settings - Fork 7.7k
-
Hello all :-)
Currently I am trying to get a simple DAC up and running which is controlled by a web server.
This code was used as a template (and works fine): https://microcontrollerslab.com/esp32-pwm-slider-web-server-control-led-brightness/
This is the modified code (the LED-commands were deleted and DAC-commands added)
#define DAC_CH1 25 string slider_value = "0"; const char* input_parameter = "value"; AsyncWebServer server(80); ....web-server part is all the same.... String processor(const String& var){ if (var == "SLIDERVALUE"){ return slider_value; } return String(); } void setup(){ Serial.begin(115200); dacWrite(DAC_CH1, slider_value); Serial.println("DAC Value 0"); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Connecting..."); } Serial.println(WiFi.localIP()); server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ request->send_P(200, "text/html", index_html, processor); }); server.on("/slider", HTTP_GET, [] (AsyncWebServerRequest *request) { String message; if (request->hasParam(input_parameter)) { message = request->getParam(input_parameter)->value(); slider_value = message; ledcWrite(DAC_CH1, slider_value.toInt()); } else { message = "No message sent"; } Serial.println(message); request->send(200, "text/plain", "OK"); }); server.begin(); } void loop() {}
Apparently there is problem with the definition of the variables and the compiler gives an error message.
"slider_value" is string, but DAC requires uint8_t as an input.
How can this problem be solved?
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 1 reply
-
Two issue there:
- You have
dacWrite(DAC_CH1, slider_value);
in the code andslider_value
is string. Line should bedacWrite(DAC_CH1, slider_value.toInt());
- In the
/slider
callback you haveledcWrite(DAC_CH1, slider_value.toInt());
, but you want DAC, so change that todacWrite(DAC_CH1, slider_value.toInt());
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks a lot. Very embarrassing, I totally overlooked the second command, which needed to be changed.
Now it works just as fine as the PWM-code.
Beta Was this translation helpful? Give feedback.