diff --git a/README.md b/README.md
index aba3da3..f3653b1 100644
--- a/README.md
+++ b/README.md
@@ -26,6 +26,21 @@ To get the IP of the board you have several options:
* The board prints the IP address it was given to the serial monitor
* Use nmap/zenmap/similar
+
+# WEB UI
+
+There is a simple HTML website that can be used to test the API and set the colors of the LED.
+From the root of the repository, open it with your favourite browser, or with python:
+
+```
+firefox $PWD/index.html
+
+# OR
+
+python3 -m http.server
+```
+
+
# API
* `/clear` clear WIFI credentials
@@ -39,6 +54,17 @@ To get the IP of the board you have several options:
* `/brightness/up` turn up the brightness (up to 255)
* `/brightness/down` turn down the brightness (down to 0)
+
+# Developing
+
+* Install arduino
+
+* Install support for ESP8266 boards in arduino: https://github.com/esp8266/Arduino
+
+* Install the fastled library in arduino: https://github.com/FastLED/FastLED/
+
+* Profit
+
# Debugging
You can use a serial monitor (e.g. in the Arduino IDE) to connect to the board.
diff --git a/jscolor-example.html b/index.html
similarity index 51%
rename from jscolor-example.html
rename to index.html
index dfc23c9..00354df 100644
--- a/jscolor-example.html
+++ b/index.html
@@ -16,6 +16,11 @@
+
+
+
+
+
diff --git a/shinesp.ino b/shinesp.ino
index 2a984b4..4274ca3 100644
--- a/shinesp.ino
+++ b/shinesp.ino
@@ -2,7 +2,9 @@
#define FASTLED_ESP8266_RAW_PIN_ORDER
#include "FastLED.h"
-#define NUM_LEDS 300
+#include "math.h"
+
+#define NUM_LEDS 150
#define DATA_PIN 0
#define led 13
@@ -17,6 +19,9 @@ CRGB leds[NUM_LEDS];
const char* customssid = "led";
const int binterval = 10;
+bool isBeating = false;
+String beatingFun = "sin";
+int beatingPeriod = 5000;
bool isOn = false;
CRGB lastColor = CRGB::White;
@@ -212,6 +217,52 @@ void handleBrightnessDown() {
httpServer.send(200, "text/plain", "Brightness set to " + String(brightness));
}
+
+void handleBeat() {
+ beatingPeriod = httpServer.arg("period").toInt();
+ beatingFun = httpServer.arg("fun");
+ // min/max don't work
+ if (beatingPeriod < 0) {
+ beatingPeriod = 5000;
+ }
+ httpServer.send(200, "text/plain", "Beating period set to " + String(beatingPeriod) + " and function set to " + beatingFun);
+}
+
+void handleBeatOn() {
+ isBeating = true;
+ httpServer.send(200, "text/plain", "Now beating!");
+}
+
+void handleBeatOff() {
+ isBeating = false;
+ FastLED.setBrightness(brightness);
+ httpServer.send(200, "text/plain", "Not beating now!");
+}
+
+int getBeatingBrightness(){
+
+ double val = 255.0;
+ if (beatingFun.equals("lin")){
+ // statements
+ val = (millis() % (beatingPeriod)) - (beatingPeriod/2.0);
+
+ if (val < 0.0) {
+ val = -val;
+ }
+ val = 255.0 * 2.0 * (val/beatingPeriod);
+ }
+ else {
+ // statements
+ val = (cos(millis()*(2.0*PI)/((double) beatingPeriod))*127+127);
+ }
+ return (int) (val*(brightness/255.0));
+}
+
+
+void beat(){
+ FastLED.setBrightness(getBeatingBrightness());
+}
+
void handleBrightness() {
int value = httpServer.arg("value").toInt();
if (value > 0) {
@@ -358,6 +409,9 @@ void setup() {
httpServer.on ( "/on", handleOn );
httpServer.on ( "/toggle", handleToggle );
httpServer.on ( "/white", handleWhite );
+ httpServer.on ( "/beat/on", handleBeatOn );
+ httpServer.on ( "/beat/off", handleBeatOff );
+ httpServer.on ( "/beat/", handleBeat );
httpServer.on ( "/brightness", handleBrightness );
httpServer.on ( "/brightness/up", handleBrightnessUp );
httpServer.on ( "/brightness/down", handleBrightnessDown );
@@ -376,5 +430,8 @@ void setup() {
void loop() {
ArduinoOTA.handle();
httpServer.handleClient();
+ if (isBeating){
+ beat();
+ }
FastLED.show();
}