Skip to content

Commit

Permalink
Use the white pin for brightness.
Browse files Browse the repository at this point in the history
  • Loading branch information
corbanmailloux committed Dec 10, 2017
1 parent 0d7b316 commit 82d5df4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 38 deletions.
26 changes: 14 additions & 12 deletions mqtt_esp8266/config-sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@
* You can then upload the code using the Arduino IDE.
*/

// Define the strip type
enum strip { BRIGHTNESS // only one color
, RGB // RGB LEDs
, RGBW // RGB LEDs with an extra white LED per LED
};
#define CONFIG_STRIP RGB
// Leave this here. These are the choices for CONFIG_STRIP below.
enum strip {
BRIGHTNESS, // only one color
RGB, // RGB LEDs
RGBW // RGB LEDs with an extra white LED per LED
};

#define CONFIG_STRIP RGB // Choose one of the options from above.

// Pins
// In case of BRIGHTNESS: only RED is used
// In case of BRIGHTNESS: only WHITE is used
// In case of RGB(W): red, green, blue(, white) is used
// All values need to be present, if they are not needed, just write any value,
// All values need to be present, if they are not needed, set to -1,
// it will be ignored.
#define CONFIG_PIN_RED 0
#define CONFIG_PIN_GREEN 2 // only needed for RGB(W) strips
#define CONFIG_PIN_BLUE 3 // only needed for RGB(W) strips
#define CONFIG_PIN_WHITE 4 // only needed for RGBW strips
#define CONFIG_PIN_RED 0 // For RGB(W)
#define CONFIG_PIN_GREEN 2 // For RGB(W)
#define CONFIG_PIN_BLUE 3 // For RGB(W)
#define CONFIG_PIN_WHITE -1 // For BRIGHTNESS and RGBW

// WiFi
#define CONFIG_WIFI_SSID "{WIFI-SSID}"
Expand Down
60 changes: 34 additions & 26 deletions mqtt_esp8266/mqtt_esp8266.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
// http://pubsubclient.knolleary.net/
#include <PubSubClient.h>

const bool rgb = CONFIG_STRIP == RGB || CONFIG_STRIP == RGBW;
const bool rgbw = CONFIG_STRIP == RGBW;
const bool rgb = (CONFIG_STRIP == RGB) || (CONFIG_STRIP == RGBW);
const bool includeWhite = (CONFIG_STRIP == BRIGHTNESS) || (CONFIG_STRIP == RGBW);
const bool debug_mode = CONFIG_DEBUG;
const bool led_invert = CONFIG_INVERT_LED_LOGIC;

Expand Down Expand Up @@ -99,13 +99,13 @@ WiFiClient espClient;
PubSubClient client(espClient);

void setup() {
pinMode(redPin, OUTPUT);
if (rgb) {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
if (rgbw) {
pinMode(whitePin, OUTPUT);
}
}
if (includeWhite) {
pinMode(whitePin, OUTPUT);
}

pinMode(txPin, OUTPUT);
Expand Down Expand Up @@ -153,7 +153,7 @@ void setup_wifi() {
"state": "ON"
}
SAMPLE PAYLOAD (RGB):
SAMPLE PAYLOAD (RGBW):
{
"brightness": 120,
"color": {
Expand Down Expand Up @@ -252,7 +252,7 @@ bool processJson(char* message) {
flashBlue = blue;
}

if (rgbw && root.containsKey("white_value")) {
if (includeWhite && root.containsKey("white_value")) {
flashWhite = root["white_value"];
}
else {
Expand Down Expand Up @@ -294,7 +294,7 @@ bool processJson(char* message) {
blue = root["color"]["b"];
}

if (rgbw && root.containsKey("white_value")) {
if (includeWhite && root.containsKey("white_value")) {
white = root["white_value"];
}

Expand Down Expand Up @@ -328,7 +328,7 @@ void sendState() {

root["brightness"] = brightness;

if (rgbw) {
if (includeWhite) {
root["white_value"] = white;
}

Expand Down Expand Up @@ -376,36 +376,44 @@ void setColor(int inR, int inG, int inB, int inW) {
inW = (255 - inW);
}

analogWrite(redPin, inR);
if (rgb) {
analogWrite(redPin, inR);
analogWrite(greenPin, inG);
analogWrite(bluePin, inB);
if (rgbw) {
analogWrite(whitePin, inW);
}
}

Serial.println("Setting LEDs:");
Serial.print(rgb ? "r: " : "");
Serial.print(inR);
if (rgb) {
Serial.print(", g: ");
Serial.print(inG);
Serial.print(", b: ");
Serial.print(inB);
if (rgbw) {
Serial.print(", w: ");
if (includeWhite) {
analogWrite(whitePin, inW);
}

if (debug_mode) {
Serial.print("Setting LEDs: {");
if (rgb) {
Serial.print("r: ");
Serial.print(inR);
Serial.print(" , g: ");
Serial.print(inG);
Serial.print(" , b: ");
Serial.print(inB);
}

if (includeWhite) {
if (rgb) {
Serial.print(", ");
}
Serial.print("w: ");
Serial.print(inW);
}

Serial.println("}");
}
Serial.println();
}

void loop() {

if (!client.connected()) {
reconnect();
}

client.loop();

if (flash) {
Expand Down

0 comments on commit 82d5df4

Please sign in to comment.