mirror of
https://github.com/balkian/shinesp.git
synced 2025-05-09 21:19:07 +00:00
Added color
This commit is contained in:
parent
f50d12dd65
commit
5de91bf984
63
shinesp.ino
63
shinesp.ino
@ -1,7 +1,7 @@
|
|||||||
#define FASTLED_ESP8266_RAW_PIN_ORDER
|
#define FASTLED_ESP8266_RAW_PIN_ORDER
|
||||||
#include "FastLED.h"
|
#include "FastLED.h"
|
||||||
|
|
||||||
#define NUM_LEDS 50
|
#define NUM_LEDS 150
|
||||||
#define DATA_PIN 0
|
#define DATA_PIN 0
|
||||||
#define led 13
|
#define led 13
|
||||||
|
|
||||||
@ -55,10 +55,10 @@ int connected = 0;
|
|||||||
// return false
|
// return false
|
||||||
//}
|
//}
|
||||||
|
|
||||||
bool connect(struct credential cred){
|
bool connect(struct credential cred) {
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
Serial.println("Trying to connect to " + cred.ssid + " with " + cred.pass);
|
Serial.println("Trying to connect to " + cred.ssid + " with " + cred.pass);
|
||||||
if(cred.ssid.length()<1){
|
if (cred.ssid.length() < 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Serial.println("Length " + cred.ssid.length());
|
Serial.println("Length " + cred.ssid.length());
|
||||||
@ -79,7 +79,7 @@ bool connect(struct credential cred){
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCredentials(struct credential cred){
|
void setCredentials(struct credential cred) {
|
||||||
String qsid = cred.ssid;
|
String qsid = cred.ssid;
|
||||||
Serial.println(qsid);
|
Serial.println(qsid);
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
@ -97,14 +97,14 @@ void setCredentials(struct credential cred){
|
|||||||
Serial.println("writing eeprom pass:");
|
Serial.println("writing eeprom pass:");
|
||||||
for (int i = 0; i < qpass.length(); ++i)
|
for (int i = 0; i < qpass.length(); ++i)
|
||||||
{
|
{
|
||||||
EEPROM.write(32+i, qpass[i]);
|
EEPROM.write(32 + i, qpass[i]);
|
||||||
Serial.print("Wrote: ");
|
Serial.print("Wrote: ");
|
||||||
Serial.println(qpass[i]);
|
Serial.println(qpass[i]);
|
||||||
}
|
}
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleSetCredentials(){
|
void handleSetCredentials() {
|
||||||
struct credential cred;
|
struct credential cred;
|
||||||
cred.ssid = "";
|
cred.ssid = "";
|
||||||
cred.pass = "";
|
cred.pass = "";
|
||||||
@ -112,7 +112,7 @@ void handleSetCredentials(){
|
|||||||
cred.ssid = httpServer.arg("ssid");
|
cred.ssid = httpServer.arg("ssid");
|
||||||
cred.pass = httpServer.arg("pass");
|
cred.pass = httpServer.arg("pass");
|
||||||
|
|
||||||
if (cred.ssid != "" && cred.pass != ""){
|
if (cred.ssid != "" && cred.pass != "") {
|
||||||
setCredentials(cred);
|
setCredentials(cred);
|
||||||
String out = "Credentials set as: " + cred.ssid + " : " + cred.pass;
|
String out = "Credentials set as: " + cred.ssid + " : " + cred.pass;
|
||||||
httpServer.send(200, "text/plain", out);
|
httpServer.send(200, "text/plain", out);
|
||||||
@ -122,32 +122,45 @@ void handleSetCredentials(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearCredentials(){
|
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();
|
EEPROM.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void handleClearCredentials(){
|
void handleClearCredentials() {
|
||||||
clearCredentials();
|
clearCredentials();
|
||||||
httpServer.send(200, "text/plain", "Cleared!");
|
httpServer.send(200, "text/plain", "Cleared!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleWhite(){
|
void handleWhite() {
|
||||||
fill_solid(leds, NUM_LEDS, CRGB(255,255,255));
|
fill_solid(leds, NUM_LEDS, CRGB(255, 255, 255));
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
httpServer.send(200, "text/plain", "White!");
|
httpServer.send(200, "text/plain", "White!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleOff(){
|
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);
|
fill_solid( leds, NUM_LEDS, CRGB::Black);
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
httpServer.send(200, "text/plain", "Off!");
|
httpServer.send(200, "text/plain", "Off!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleBrightness(){
|
void handleBrightness() {
|
||||||
int value = httpServer.arg("value").toInt();
|
int value = httpServer.arg("value").toInt();
|
||||||
if(value>0){
|
if (value > 0) {
|
||||||
FastLED.setBrightness(value);
|
FastLED.setBrightness(value);
|
||||||
httpServer.send(200, "text/plain", "Brightness set to " + String(value));
|
httpServer.send(200, "text/plain", "Brightness set to " + String(value));
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
@ -186,9 +199,9 @@ void handleRoot() {
|
|||||||
);
|
);
|
||||||
httpServer.send ( 200, "text/html", temp );
|
httpServer.send ( 200, "text/html", temp );
|
||||||
digitalWrite ( led, 0 );
|
digitalWrite ( led, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupAP(){
|
void setupAP() {
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.disconnect();
|
WiFi.disconnect();
|
||||||
delay(100);
|
delay(100);
|
||||||
@ -201,7 +214,7 @@ void setupAP(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void handleLoop() {
|
void handleLoop() {
|
||||||
for(int dot = 0; dot < NUM_LEDS; dot++) {
|
for (int dot = 0; dot < NUM_LEDS; dot++) {
|
||||||
leds[dot] = CRGB::Blue;
|
leds[dot] = CRGB::Blue;
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
// clear this led for the next time around the loop
|
// clear this led for the next time around the loop
|
||||||
@ -212,7 +225,7 @@ void handleLoop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct credential getCredentials(){
|
struct credential getCredentials() {
|
||||||
Serial.println("Getting credentials from EEPROM");
|
Serial.println("Getting credentials from EEPROM");
|
||||||
struct credential cred;
|
struct credential cred;
|
||||||
cred.ssid = "";
|
cred.ssid = "";
|
||||||
@ -242,7 +255,7 @@ void setup() {
|
|||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
|
|
||||||
struct credential cred = getCredentials();
|
struct credential cred = getCredentials();
|
||||||
if (!connect(cred)){
|
if (!connect(cred)) {
|
||||||
setupAP();
|
setupAP();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,19 +297,21 @@ void setup() {
|
|||||||
httpServer.on ( "/loop", handleLoop );
|
httpServer.on ( "/loop", handleLoop );
|
||||||
httpServer.on ( "/", handleRoot );
|
httpServer.on ( "/", handleRoot );
|
||||||
httpServer.on ( "/clear", handleClearCredentials );
|
httpServer.on ( "/clear", handleClearCredentials );
|
||||||
httpServer.on ( "/set", handleSetCredentials );
|
httpServer.on ( "/credentials", handleSetCredentials );
|
||||||
httpServer.on ( "/white", handleWhite );
|
httpServer.on ( "/white", handleWhite );
|
||||||
|
httpServer.on ( "/color", handleColor );
|
||||||
httpServer.on ( "/off", handleOff );
|
httpServer.on ( "/off", handleOff );
|
||||||
httpServer.on ( "/brightness", handleBrightness );
|
httpServer.on ( "/brightness", handleBrightness );
|
||||||
httpServer.begin();
|
httpServer.begin();
|
||||||
|
|
||||||
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
|
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
|
||||||
FastLED.setDither(0);
|
// FastLED.setDither(0);
|
||||||
// FastLED.setBrightness(200);
|
FastLED.setBrightness(100);
|
||||||
FastLED.setMaxPowerInVoltsAndMilliamps(5, 4000);
|
FastLED.setMaxPowerInVoltsAndMilliamps(5, 20000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
httpServer.handleClient();
|
httpServer.handleClient();
|
||||||
|
FastLED.show();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user