s00500 / ESPUI

A simple web user interface library for ESP32 and ESP8266
https://valencia.lbsfilm.at/midterm-presentation/
Other
923 stars 174 forks source link

Multiple sliders #205

Open Niutonian opened 2 years ago

Niutonian commented 2 years ago

Hello, I love your library, and I would like to know if you could help me figure out a solution to my problem.

I am trying to use multiple sliders, but I can't figure out how to pass different values for each.

I'm a novice, so I may not fully understand how to do it. Here is my code:

Above setup: ` int sliderValueWithOffset; int cRed; int cGreen; int cBlue;

void slider(Control* sender, int type) { Serial.print("Slider: ID: "); Serial.print(sender->id); Serial.print(", Value: "); Serial.println(sender->value); // Like all Control Values in ESPUI slider values are Strings. To use them as int simply do this: sliderValueWithOffset = sender->value.toInt() + 100;

}`

in setup: cRed = ESPUI.slider("Slider Red", &slider, ControlColor::Alizarin, 255); cGreen =ESPUI.slider("Slider Green", &slider, ControlColor::Alizarin, 0); cBlue = ESPUI.slider("Slider Blue", &slider, ControlColor::Alizarin, 0);

in loop: ` Serial.println(cRed); Serial.println(cGreen); Serial.println(cBlue);

if (cRed = 9) {
  int colorR = sliderValueWithOffset;
  Serial.print("Red:: ");
  Serial.println(sliderValueWithOffset);
}

if (cGreen = 12) {
  int colorG = sliderValueWithOffset;
  Serial.print("Green:: ");
  Serial.println(sliderValueWithOffset);
}

if (cBlue = 15) {
  int colorB = sliderValueWithOffset;
  Serial.print("Blue:: ");
  Serial.println(sliderValueWithOffset);
}

` all these pass the same value, how should I separate them?

Thank you

thomastech commented 2 years ago

There's syntax issues with the if conditional statements.

Change:

if (cRed = 9) {
if (cGreen = 12) {
if (cBlue = 15) {

To:

if (cRed == 9) {
if (cGreen == 12) {
if (cBlue == 15) {

I didn't review your code for any other errors, just noticed the conditional typos.

Niutonian commented 2 years ago

Thank you for your help, I will give it a try and post the entire code if it works.