So I’ve been playing with WLED for a little while and wanted a simple hard-button remote for just turning on/off, brightness, and maybe cycle through effects. Now, not being any kind of coder but able to cut-and-paste my way through things, ok at following reference designs, and mildly handy with a soldering iron, I figured I’d give it a try. As a working prototype here’s what I have so far after a couple days…
I just blended together the BasicHTTPClient, and Digital>Button example sketches from the Arduino IDE to get something that takes button presses and sends corresponding HTTP API commands to the WLED controller.
/**
BasicHTTPClient.ino
Created on: 24.05.2015
*/
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
ESP8266WiFiMulti WiFiMulti;
const int button1Pin = 2; // the number of the pushbutton pin
const int button2Pin = 0;
const int button3Pin = 4; //ADDED EXTERNAL 100K PULL-UP T.O.
const int button4Pin = 5; //ADDED EXTERNAL 100K PULL-UP T.O.
int button1State = 0; // variable for reading the pushbutton status
int button2State = 0;
int button3State = 0;
int button4State = 0;
void setup() {
// initialize the pushbutton pin as an input:
pinMode(button1Pin, INPUT);
pinMode(button2Pin, INPUT);
pinMode(button3Pin, INPUT);
pinMode(button4Pin, INPUT);
Serial.begin(115200);
// Serial.setDebugOutput(true);
Serial.println();
Serial.println();
Serial.println();
for (uint8_t t = 4; t > 0; t--) {
Serial.printf("[SETUP] WAIT %d...\n", t);
Serial.flush();
delay(1000);
}
WiFi.mode(WIFI_STA);
WiFiMulti.addAP("SSID", "PASSWORD");
}
void loop() {
button1State = digitalRead(button1Pin);
button2State = digitalRead(button2Pin);
button3State = digitalRead(button3Pin);
button4State = digitalRead(button4Pin);
// wait for WiFi connection
if ((WiFiMulti.run() == WL_CONNECTED)) {
WiFiClient client;
HTTPClient http;
//Serial.print("[HTTP] begin...\n");
if (button1State == LOW)
(http.begin(client, "http://192.168.1.66/win&T=1")); //WLED ON T.O.
if (button2State == LOW)
(http.begin(client, "http://192.168.1.66/win&T=0")); //WLED OFF T.O.
if (button3State == LOW)
(http.begin(client, "http://192.168.1.66/win&A=~5")); //INCREMENT MASTER BRIGHTNESS T.O.
if (button4State == LOW)
(http.begin(client, "http://192.168.1.66/win&A=~-5")); //DECREMENT MASTER BRIGHTNESS T.O.
//Serial.print("[HTTP] GET...\n");
// start connection and send HTTP header
int httpCode = http.GET();
http.end();
} else {
Serial.printf("[HTTP} Unable to connect\n");
}
delay(100);
}
I removed, or commented-out unnecessary stuff to just get what I needed. I’m sure it’s not the most elegant, but it actually works quite well.
My end goal for this project is to have a desktop unit, and then also something that will actually be able to be wired into an in-wall HV box, like any common Decora-style switch or dimmer. This way it will blend into any room with normal light switches, similar to Lutron SeeTouch keypads.
Anyway, I searched around here, but couldn’t find anything similar so here we are. Let me know if I totally missed something like this, or if I’m re-inventing the wheel here. Comments and suggestions welcome.
Tim