Skip to content

Commit

Permalink
Add an inversion mode, per #18.
Browse files Browse the repository at this point in the history
  • Loading branch information
corbanmailloux committed Aug 1, 2017
1 parent 2aaa463 commit 318d6d5
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 2 deletions.
5 changes: 5 additions & 0 deletions mqtt_esp8266_brightness/config-sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@
// Default number of flashes if no value was given
#define CONFIG_DEFAULT_FLASH_LENGTH 2

// Reverse the LED logic
// false: 0 (off) - 255 (bright)
// true: 255 (off) - 0 (bright)
#define CONFIG_INVERT_LED_LOGIC false

// Enables Serial and print statements
#define CONFIG_DEBUG false
6 changes: 5 additions & 1 deletion mqtt_esp8266_brightness/mqtt_esp8266_brightness.ino
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <PubSubClient.h>

const bool debug_mode = CONFIG_DEBUG;
const bool led_invert = CONFIG_INVERT_LED_LOGIC;

const int redPin = CONFIG_PIN_LIGHT;
const int txPin = BUILTIN_LED; // On-board blue LED
Expand Down Expand Up @@ -96,7 +97,6 @@ void setup() {
}

void setup_wifi() {

delay(10);
// We start by connecting to a WiFi network
Serial.println();
Expand Down Expand Up @@ -276,6 +276,10 @@ void reconnect() {
}

void setColor(int inR) { //, int inG, int inB) {
if (led_invert) {
inR = (255 - inR);
}

analogWrite(redPin, inR);
// analogWrite(greenPin, inG);
// analogWrite(bluePin, inB);
Expand Down
5 changes: 5 additions & 0 deletions mqtt_esp8266_rgb/config-sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,10 @@
#define CONFIG_COLORFADE_TIME_SLOW 10
#define CONFIG_COLORFADE_TIME_FAST 3

// Reverse the LED logic
// false: 0 (off) - 255 (bright)
// true: 255 (off) - 0 (bright)
#define CONFIG_INVERT_LED_LOGIC false

// Enables Serial and print statements
#define CONFIG_DEBUG false
9 changes: 8 additions & 1 deletion mqtt_esp8266_rgb/mqtt_esp8266_rgb.ino
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <PubSubClient.h>

const bool debug_mode = CONFIG_DEBUG;
const bool led_invert = CONFIG_INVERT_LED_LOGIC;

const int redPin = CONFIG_PIN_RED;
const int txPin = BUILTIN_LED; // On-board blue LED
Expand Down Expand Up @@ -104,7 +105,7 @@ void setup() {
if (debug_mode) {
Serial.begin(115200);
}

setup_wifi();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
Expand Down Expand Up @@ -328,6 +329,12 @@ void reconnect() {
}

void setColor(int inR, int inG, int inB) {
if (led_invert) {
inR = (255 - inR);
inG = (255 - inG);
inB = (255 - inB);
}

analogWrite(redPin, inR);
analogWrite(greenPin, inG);
analogWrite(bluePin, inB);
Expand Down
5 changes: 5 additions & 0 deletions mqtt_esp8266_rgbw/config-sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,10 @@
#define CONFIG_COLORFADE_TIME_SLOW 10
#define CONFIG_COLORFADE_TIME_FAST 3

// Reverse the LED logic
// false: 0 (off) - 255 (bright)
// true: 255 (off) - 0 (bright)
#define CONFIG_INVERT_LED_LOGIC false

// Enables Serial and print statements
#define CONFIG_DEBUG false
8 changes: 8 additions & 0 deletions mqtt_esp8266_rgbw/mqtt_esp8266_rgbw.ino
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <PubSubClient.h>

const bool debug_mode = CONFIG_DEBUG;
const bool led_invert = CONFIG_INVERT_LED_LOGIC;

const int redPin = CONFIG_PIN_RED;
const int txPin = BUILTIN_LED; // On-board blue LED
Expand Down Expand Up @@ -350,6 +351,13 @@ void reconnect() {
}

void setColor(int inR, int inG, int inB, int inW) {
if (led_invert) {
inR = (255 - inR);
inG = (255 - inG);
inB = (255 - inB);
inW = (255 - inW);
}

analogWrite(redPin, inR);
analogWrite(greenPin, inG);
analogWrite(bluePin, inB);
Expand Down

0 comments on commit 318d6d5

Please sign in to comment.