corbanmailloux / esp-mqtt-rgb-led

MQTT RGB LEDs Using JSON for Home Assistant
MIT License
270 stars 74 forks source link

Added inverson function #18

Closed linker3000 closed 7 years ago

linker3000 commented 7 years ago

Hi, I modified the code to add a functional invert option - not being a full github guru, I'm just documenting it here!!

The purpose was to invert the output driver ranges so that I could use the code for a single RGB LED (Common anode) built into a dummy 'mains lamp' linked directly to the ESP I/O pins through current limiting resistors...the arrangement meant that a GPIO of 255 is full off, and 0 is full on (inverted logic)

config.h - added a definition:

//NK LED Type - Common anode uses reverse value logic for intensities
#define MODE_INVERT 1

In main code - added a variable at line 20:

const int modeInvert = MODE_INVERT;

Modified setColor:

 if (modeInvert == 1)
  {
    analogWrite(redPin, 255 - inR);
    analogWrite(greenPin, 255 - inG);
    analogWrite(bluePin, 255 - inB);
  }
  else
  {
  analogWrite(redPin, inR);
  analogWrite(greenPin, inG);
  analogWrite(bluePin, inB);
  }
corbanmailloux commented 7 years ago

@linker3000 I've added this functionality in the latest version. Take a look at the config-sample.h file for a quick explanation.