1
0
mirror of https://github.com/balkian/shinesp.git synced 2024-12-22 05:28:12 +00:00

Added color

This commit is contained in:
J. Fernando Sánchez 2017-01-04 09:47:58 +01:00
parent f50d12dd65
commit 5de91bf984

View File

@ -1,7 +1,7 @@
#define FASTLED_ESP8266_RAW_PIN_ORDER
#include "FastLED.h"
#define NUM_LEDS 50
#define NUM_LEDS 150
#define DATA_PIN 0
#define led 13
@ -123,7 +123,9 @@ void handleSetCredentials(){
}
void clearCredentials() {
for (int i = 0; i < 96; ++i) { EEPROM.write(i, 0); }
for (int i = 0; i < 96; ++i) {
EEPROM.write(i, 0);
}
EEPROM.commit();
}
@ -139,6 +141,17 @@ void handleWhite(){
httpServer.send(200, "text/plain", "White!");
}
void handleColor() {
int r = httpServer.arg("r").toInt();
int g = httpServer.arg("g").toInt();
int b = httpServer.arg("b").toInt();
char msg[400];
fill_solid( leds, NUM_LEDS, CRGB(r,g,b));
FastLED.show();
snprintf ( msg, 400, "RGB=(%d, %d, %d)", r, g, b);
httpServer.send(200, "text/plain", msg);
}
void handleOff() {
fill_solid( leds, NUM_LEDS, CRGB::Black);
FastLED.show();
@ -284,19 +297,21 @@ void setup() {
httpServer.on ( "/loop", handleLoop );
httpServer.on ( "/", handleRoot );
httpServer.on ( "/clear", handleClearCredentials );
httpServer.on ( "/set", handleSetCredentials );
httpServer.on ( "/credentials", handleSetCredentials );
httpServer.on ( "/white", handleWhite );
httpServer.on ( "/color", handleColor );
httpServer.on ( "/off", handleOff );
httpServer.on ( "/brightness", handleBrightness );
httpServer.begin();
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.setDither(0);
// FastLED.setBrightness(200);
FastLED.setMaxPowerInVoltsAndMilliamps(5, 4000);
// FastLED.setDither(0);
FastLED.setBrightness(100);
FastLED.setMaxPowerInVoltsAndMilliamps(5, 20000);
}
void loop() {
ArduinoOTA.handle();
httpServer.handleClient();
FastLED.show();
}