Analog Input?

Not sure if anyone else would be interested, so I’ll throw it out for comment…

Support for an analog input to control the master brightness.

I believe such an option would be useful! It is also quite versatile, for example using a potentiometer is possible as well as a simple photo resistor to get some auto-brightness control.

3 Likes

I support this and can think of several useful things you could do with analog inputs. :thinking::grin:

1 Like

-> simple photo resistor to get some auto-brightness control.
That is one thing i played with. But that is also a thing for a next version. First we have to think about the changes that will come and put it all togehter that wled will be stable at it is in the moment and in the future.

Silly me. I grabbed an ESP8266 and thought it would be as simple as…

  if (WLED_CONNECTED){
    int ard=analogRead(A0);
    byte mb=map(ard, 0, 1023, 0, 255);
    bri=mb;
    yield();
  }

…but no! :laughing:

What am I missing?

Add a colorUpdated(2); after bri=mb; :slight_smile:

Remember that this will completely disable brightness and on/off control via WiFi - i’d suggest checking if mb has changed and only change bri in that case, but it might be more complicated than that since analog readings often fluctuate a bit.

1 Like

Thanks. Sounds like I should dig into adding a checkbox in Settings for this. :smiley:

Update: It’s now working :partying_face: , but I can’t get to the web page after I put it on my network. :open_mouth:

Note: I just found that this does need to be only when WLED_CONNECTED is true. Seems to block the AP.

So strange! I’ve added a checkbox on the macro HTML page and some code to push that into a variable to enable the input to drive brightness. All is well until I check the box. At that point, it stops serving web pages. Code below. Note that this is on an ESP8266, if that matters.

Any ideas?

void userLoop()
{
    if (WLED_CONNECTED && pwmEnable){
      byte mb4 = bri;                       // save current brightness
      int ard=analogRead(A0);
      byte mb=map(ard, 0, 1023, 0, 255);  // map 1023 to 255
      if (mb4 != mb){                     // only change if different
        bri=mb;
        colorUpdated(2);
    }
    yield();
  }
}

Not entirely sure, but maybe colorUpdated(5); would work (instead of 2), since WLED may attempt to send sync packets in every loop if mb fluctuates. Even so, this might take too much time trying to process the change, therefore another idea would be to add a timer to limit how often the analog reading is taken:

unsigned long lastRead = 0;

void userLoop()
{
  if (WLED_CONNECTED && pwmEnable && millis() - lastRead > 100){
    lastRead = millis();
    byte mb4 = bri;                       // save current brightness
    int ard=analogRead(A0);
    byte mb=map(ard, 0, 1023, 0, 255);  // map 1023 to 255
    if (mb4 != mb){                     // only change if different
      bri=mb;
      colorUpdated(2);
    }
    yield();
  }
}

Maybe this can help :slight_smile:

1 Like

I’ll try the 5 first! Nope. On to the timing…

Also, I just realized that I need to save that enable variable to EEPROM. :smiley:

Update: Adding that time check didn’t fix it. :frowning:

To be clear, I can see the IP in my list of connected-devices, I cannot pull up any of the web pages, but the brightness is following the analog signal.

Again, this is on an ESP8266. I still need to try it on an ESP32.