TidalPaladin / ESPLed

Library to control Leds on the ESP8226 and ESP32 under Arduino
GNU General Public License v3.0
2 stars 1 forks source link

Bi-Colour LED support #2

Open marrold opened 6 years ago

marrold commented 6 years ago

Hi, First of all thanks for creating this great library.

It would be nice if there was support for Bi-Colour LEDs by defining the two pins the LED is connected two and then interacting with them that way.

Thanks again

TidalPaladin commented 6 years ago

Glad to hear the library is useful! I'm currently working on an overhaul - giving methods more sensible names and better organizing things. I will definitely add bi-color LEDs to the todo list :)

For now you can get some level of functionality by creating two separate Led objects, one for each color. Blink and pulse probably wont be timed well, but you could turn each object on to a different brightness to create different colors. For example

Led red(pin1);
Led blue(pin2);
red.on(50);
blue.on(50);
// Purple now?

Can you suggest any methods you want to see? I'm thinking something like

led.on(color1_brightness, color2_brightness);
led.blink(color1_brightness, color2_brightness);
led.pulse(/* A range of colors to pulse through*/);
marrold commented 6 years ago

Actually I was thinking the two pin bi-colour LEDs, but the three pin ones probably make more sense.

Your proposed methods for three pin LEDs look perfect.

Here's my suggestions for two leads-

BiLed status;
status.add(red, pin1);
status.add(green, pin2);

status.on(green, 50)
status.on(red, 50)

status.blink(red)
status.setDuration(200);
status.setInterval(2000);
status.blink().start();

status.blink(both)
status.setDuration(200);
status.setInterval(2000);
status.blink().start();

status.blink(red)
status.setMaxBrightness(100);
status.setPeriod(1000);
status.setRefreshRate(50);
status.pulse().start();

status.blink(both)
status.setMaxBrightness(100);
status.setPeriod(1000);
status.setRefreshRate(50);
status.pulse().start(); 

Thanks again