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.

1 Like

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.

4 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.

Hi, anyone has used Analog0 to switch on/off automatically wled?

It is in the latest code as an analog button
You attach potentiometer and then you can control brightness with it.

I had in mind something different, use a fotoresistor (connected with trimmer) to turn on automatically lights when it’s getting dark…
Talking about hardware it should be easy, a trimmer 100k connected to +3.3v, then fotoresistor to ground, in the middle A0, but not really sure about the electrolysis effect having place on the fotoresistor with constant current, after long time (may years). It’s always better to give it an alternate current, I’ve to think about.

Talking about software, it would be necessary to set only (on web interface) the triggers (expressed in volts or ADC value to 1023 as you like) when it switches on and off. May ou kindly implement that too? Please print also the actual value read, thanks!

There is a usermod for that I think. Look for it in usermods subfolder.

With a proper NTP configuration and your WLED install’s LAT/LON, you can schedule WLED to come on when the sun sets based on your location in the world. No analog input required. Of course during an eclipse, your WLED instance will not come on.

This is really interesting… thanks. I’ve found it but I can’t configure latitude for trying… where is it?
I’m living in Saint Petersburg (Russia) and here light conditions are really different from winter to summer, even cloudly or sunny can change it too, and white nights too…
I would prefer to measure the light conditions, I’ll give a try with an empty 8266

Time & Macros :wink:

While you wait to get your analog input installed, wired, WLED analog input calibrated and code customized to suit your needs, you could try adding the St Petersburg lat 59.9 N, lon 30.3 E

Mate I can’t find the place where I can set LAT/LON, I’ve mostly searched on the time settings. Where can I insert them? Thanks