My wife asked me to set up some LED strips on her mirror to mimic the special makeup light systems you can buy.
Create a simple project with 2 sliders on V0
and V1
.
The physical box includes a big old nodemcu esp8266, a momentary button and a potentiometer.
The potentiometer exclusively controls the brightness of the LEDs.
The button switches between modes: OFF, BRIGHT WHITE (almost blue), CUSTOM (controled via blynk and remembers it’s state upon boot).
The code is rather simple.
//#define BLYNK_DEBUG
//#define BLYNK_PRINT Serial
#include <ArduinoOTA.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <FastLED.h>
#define DATA_PIN 2
#define NUM_LEDS 126
#define vPIN_HUE V0
#define vPIN_SAT V1
CRGB leds[NUM_LEDS];
int varHue;
int varSaturation;
int varBrightness;
int varMode;
boolean ButtonCurState;
boolean ButtonLastState = LOW;
uint8_t gHue = 0;
char auth[] = "xxxxx";
char ssid[] = "xxxxx";
char pass[] = "xxxxx";
BLYNK_CONNECTED() {
Blynk.syncVirtual(vPIN_HUE, vPIN_SAT);
}
BLYNK_WRITE(vPIN_HUE) {
varHue = param.asInt();
}
BLYNK_WRITE(vPIN_SAT) {
varSaturation = param.asInt();
}
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
Blynk.begin(auth, ssid, pass);
while (Blynk.connect() == false) {}
ArduinoOTA.setHostname("LED-MAKEUP-MIRROR");
ArduinoOTA.begin();
pinMode(15, OUTPUT);
pinMode(13, INPUT);
varHue = 48;
varSaturation = 0;
varBrightness = 255;
varMode = 0;
FastLED.setMaxPowerInVoltsAndMilliamps(5, 2000);
FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
}
void loop() {
Blynk.run();
ArduinoOTA.handle();
manualButton();
switch (varMode) {
case 1:
// bright white (daylight)
varBrightness = map(analogRead(A0), 0, 1023, 0, 255);
fill_solid(leds, NUM_LEDS, CHSV(0, 0, varBrightness));
break;
case 2:
// custom hue/sat
varBrightness = map(analogRead(A0), 0, 1023, 0, 255);
fill_solid(leds, NUM_LEDS, CHSV(varHue, varSaturation, varBrightness));
break;
default:
// off
varBrightness = 0;
fill_solid(leds, NUM_LEDS, CHSV(0, 0, varBrightness));
break;
}
FastLED.show();
}
void manualButton() {
ButtonCurState = digitalRead(13);
if (ButtonCurState == HIGH && ButtonLastState == LOW) {
ButtonLastState = ButtonCurState;
varMode++;
if (varMode > 2) varMode = 0;
delay(10);
}
}