Multiple sliders
Niutonian opened this issue · comments
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
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.
- Thomas
Thank you for your help,
I will give it a try and post the entire code if it works.