3 Commits

12 changed files with 555 additions and 622 deletions

View File

@ -6,14 +6,38 @@ Control an addressable LED strip with an ESP8266 via a web browser or infrared r
Hardware Hardware
-------- --------
An ESP8266 development board, such as the [Adafruit HUZZAH ESP8266 Breakout]: ##### ESP8266 development board
[![Wemos D1 Mini Pro & Headers](https://ae01.alicdn.com/kf/HTB1P1KVaMsSMeJjSsphq6xuJFXah/WEMOS-D1-mini-Pro-V1-1-0-16M-bytes-external-antenna-connector-ESP8266-WIFI-Internet-of.jpg_200x200.jpg)](https://www.aliexpress.com/item/WEMOS-D1-mini-Pro-16M-bytes-external-antenna-connector-ESP8266-WIFI-Internet-of-Things-development-board/32724692514.html)
[Wemos D1 Mini Pro & Headers](https://www.aliexpress.com/item/WEMOS-D1-mini-Pro-16M-bytes-external-antenna-connector-ESP8266-WIFI-Internet-of-Things-development-board/32724692514.html)
or
[![Adafruit HUZZAH ESP8266 Breakout](https://cdn-shop.adafruit.com/310x233/2471-10.jpg)](https://www.adafruit.com/products/2471) [![Adafruit HUZZAH ESP8266 Breakout](https://cdn-shop.adafruit.com/310x233/2471-10.jpg)](https://www.adafruit.com/products/2471)
Addressable LED strip, such as the [Adafruit NeoPixel Ring]: [Adafruit HUZZAH ESP8266 Breakout](https://www.adafruit.com/products/2471)
##### Addressable LED strip
[![Adafruit NeoPixel Ring](https://www.adafruit.com/images/145x109/1586-00.jpg)](https://www.adafruit.com/product/1586) [![Adafruit NeoPixel Ring](https://www.adafruit.com/images/145x109/1586-00.jpg)](https://www.adafruit.com/product/1586)
[Adafruit NeoPixel Ring]
Other hardware:
* [3.3V to 5V Logic Level Shifter](http://www.digikey.com/product-detail/en/texas-instruments/SN74HCT245N/296-1612-5-ND/277258) (required if LEDs "glitch")
Recommended by [Adafruit NeoPixel "Best Practices"](https://learn.adafruit.com/adafruit-neopixel-uberguide/best-practices) to help protect LEDs from current onrush:
* [1000µF Capacitor](http://www.digikey.com/product-detail/en/panasonic-electronic-components/ECA-1EM102/P5156-ND/245015)
* [300 to 500 Ohm resistor](https://www.digikey.com/product-detail/en/stackpole-electronics-inc/CF14JT470R/CF14JT470RCT-ND/1830342)
Optional shield to make everything more tidy:
[![Wemos D1 Mini ESP8266 LED & Level Shifter Shield](https://d3s5r33r268y59.cloudfront.net/13194/products/thumbs/2017-05-06T15:02:37.208Z-IMG_20170506_100623.jpg.114x76_q85_pad_rcrop.jpg)](https://www.tindie.com/products/jasoncoon/wemos-d1-mini-esp8266-led-and-level-shifter-shield/)
[Wemos D1 Mini ESP8266 LED & Level Shifter Shield](https://www.tindie.com/products/jasoncoon/wemos-d1-mini-esp8266-led-and-level-shifter-shield)
Features Features
-------- --------
* Turn the NeoPixel Ring on and off * Turn the NeoPixel Ring on and off
@ -41,7 +65,7 @@ The app is installed via the Arduino IDE which can be [downloaded here](https://
The app depends on the following libraries. They must either be downloaded from GitHub and placed in the Arduino 'libraries' folder, or installed as [described here](https://www.arduino.cc/en/Guide/Libraries) by using the Arduino library manager. The app depends on the following libraries. They must either be downloaded from GitHub and placed in the Arduino 'libraries' folder, or installed as [described here](https://www.arduino.cc/en/Guide/Libraries) by using the Arduino library manager.
* [FastLED](https://github.com/FastLED/FastLED) * [FastLED](https://github.com/FastLED/FastLED)
* [IRremoteESP8266](https://github.com/markszabo/IRremoteESP8266) * [IRremoteESP8266](https://github.com/sebastienwarin/IRremoteESP8266)
* [Arduino WebSockets](https://github.com/Links2004/arduinoWebSockets) * [Arduino WebSockets](https://github.com/Links2004/arduinoWebSockets)
Download the app code from GitHub using the green Clone or Download button from [the GitHub project main page](https://github.com/jasoncoon/esp8266-fastled-webserver) and click Download ZIP. Decompress the ZIP file in your Arduino sketch folder. Download the app code from GitHub using the green Clone or Download button from [the GitHub project main page](https://github.com/jasoncoon/esp8266-fastled-webserver) and click Download ZIP. Decompress the ZIP file in your Arduino sketch folder.
@ -71,7 +95,7 @@ The firmware implements basic [RESTful web services](https://en.wikipedia.org/wi
Infrared Remote Control Infrared Remote Control
----------------------- -----------------------
Control via infrared remote control is also supported, via the [ESP8266 port of the IRremote library](https://github.com/markszabo/IRremoteESP8266). Control via infrared remote control is also supported, via the [ESP8266 port of the IRremote library](https://github.com/sebastienwarin/IRremoteESP8266).
[Adafruit NeoPixel Ring]:https://www.adafruit.com/product/1586 [Adafruit NeoPixel Ring]:https://www.adafruit.com/product/1586
[Adafruit HUZZAH ESP8266 Breakout]:https://www.adafruit.com/products/2471 [Adafruit HUZZAH ESP8266 Breakout]:https://www.adafruit.com/products/2471

65
Text.h
View File

@ -1,65 +0,0 @@
bool mask[NUM_LEDS];
const byte digits4x8[8 * 10] = {
0x06, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x06, // 0
0x04, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04, 0x0e, // 1
0x06, 0x09, 0x08, 0x08, 0x04, 0x02, 0x01, 0x0f, // 2
0x06, 0x09, 0x08, 0x04, 0x08, 0x08, 0x09, 0x06, // 3
0x04, 0x05, 0x05, 0x05, 0x0f, 0x04, 0x04, 0x04, // 4
0x0f, 0x01, 0x01, 0x07, 0x08, 0x08, 0x09, 0x06, // 5
0x06, 0x09, 0x01, 0x07, 0x09, 0x09, 0x09, 0x06, // 6
0x0f, 0x08, 0x08, 0x04, 0x02, 0x01, 0x01, 0x01, // 7
0x06, 0x09, 0x09, 0x06, 0x09, 0x09, 0x09, 0x06, // 8
0x06, 0x09, 0x09, 0x09, 0x0e, 0x08, 0x09, 0x06, // 9
};
// preceed with a call to fillMask(false);
// set mask to true where digit should light
void digit(byte start, byte d) {
byte row, col;
for (col = 0; col < 4; col++) {
for (row = 0; row < 8; row++) {
if ((digits4x8[d * 8 + row] >> col) & 1) {
togglePixelMask(row, col + start, true);
}
else {
}
}
}
}
void displayNum(uint32_t n) {
digit( 0, (n / 10000) % 10);
digit( 5, (n / 1000) % 10);
digit(10, (n / 100) % 10);
digit(15, (n / 10) % 10);
digit(20, (n / 1) % 10);
}
void displayTime(uint32_t tm) {
uint8_t hh = (tm / 3600) % 12;
uint8_t mm = (tm / 60) % 60;
uint8_t ss = (tm) % 60;
if (hh > 9) {
digit( 1, hh / 10);
}
digit( 6, hh % 10);
setPixelMask(2, 11, true);
setPixelMask(3, 11, true);
setPixelMask(5, 11, true);
setPixelMask(6, 11, true);
digit(13, mm / 10);
digit(18, mm % 10);
if (hh > 9) {
digit( 1 + 24, hh / 10);
}
digit( 6 + 24, hh % 10);
setPixelMask(2, 11 + 24, true);
setPixelMask(3, 11 + 24, true);
setPixelMask(5, 11 + 24, true);
setPixelMask(6, 11 + 24, true);
digit(13 + 24, mm / 10);
digit(18 + 24, mm % 10);
}

157
WiFi.h Normal file
View File

@ -0,0 +1,157 @@
//#include <DNSServer.h>
//DNSServer dnsServer;
//const byte DNS_PORT = 53;
// AP mode password
const char WiFiAPPSK[] = "";
// Wi-Fi network to connect to (leave blank to connect to saved network, or to start in AP mode)
const char* ssid = "";
const char* password = "";
#define HOSTNAME "ESP8266-" ///< Hostname. The initializeWiFi function adds the Chip ID at the end.
#define DEBUG_WIFI 1
WiFiMode mode = WIFI_STA; // connect to existing Wi-Fi network
//WiFiMode mode = WIFI_AP; // act as an Access Point, creating a new Wi-Fi network
//WiFiMode mode = WIFI_AP_STA; // act as both a client and Access Point (mesh mode)
template <typename Generic>
void debugPrint(Generic text) {
if (DEBUG_WIFI) {
Serial.print(text);
}
}
template <typename Generic>
void debugPrintln(Generic text) {
if (DEBUG_WIFI) {
Serial.println(text);
}
}
String getWiFiJson() {
String hostname = String(HOSTNAME);
hostname += String(ESP.getChipId(), HEX);
String json = "{";
json += "\"status\":\"" + String(WiFi.status()) + "\"";
json += ",\"localIP\":\"" + WiFi.localIP().toString() + "\"";
json += ",\"softAPIP\":\"" + WiFi.softAPIP().toString() + "\"";
json += ",\"hostname\":\"" + hostname + "\"";
json += ",\"ssid\":\"" + WiFi.SSID() + "\"";
json += ",\"rssi\":\"" + String(WiFi.RSSI()) + "\"";
json += ",\"networks\":[";
byte ssidCount = WiFi.scanNetworks();
for (byte i = 0; i < ssidCount; i++) {
if (i > 0)
json += ",";
json += "{\"name\":\"" + WiFi.SSID(i) + "\",\"rssi\":\"" + String(WiFi.RSSI(i)) + "\"}";
}
json += "]";
json += "}";
return json;
}
void initializeWiFi() {
// Set Hostname.
String hostname = String(HOSTNAME);
hostname += String(ESP.getChipId(), HEX);
WiFi.hostname(hostname);
// Print hostname.
Serial.println("Hostname: " + hostname);
char hostnameChar[hostname.length() + 1];
memset(hostnameChar, 0, hostname.length() + 1);
for (uint8_t i = 0; i < hostname.length(); i++)
hostnameChar[i] = hostname.charAt(i);
// MDNS.begin(hostnameChar);
// Add service to MDNS-SD
// MDNS.addService("http", "tcp", 80);
// attempt to connect; should it fail, fall back to AP mode
// WiFi.mode(WIFI_STA);
String stored_ssid = WiFi.SSID();
if (ssid != NULL && password != NULL &&
ssid != "" && password != "") {
debugPrint("WiFi mode: ");
debugPrintln(WIFI_STA);
WiFi.mode(WIFI_STA);
debugPrint("Connecting to hard-coded SSID: ");
debugPrintln(stored_ssid);
WiFi.begin(ssid, password);
}
else if (stored_ssid != NULL && stored_ssid != "") {
debugPrint("WiFi mode: ");
debugPrintln(WIFI_STA);
WiFi.mode(WIFI_STA);
debugPrint("Connecting to stored SSID: ");
debugPrintln(stored_ssid);
WiFi.begin();
}
else {
debugPrintln("No stored SSID");
debugPrint("Starting soft AP: ");
debugPrintln(hostnameChar);
WiFi.mode(WIFI_AP);
if (WiFiAPPSK != NULL) {
debugPrint(WiFi.softAP(hostnameChar, WiFiAPPSK) ? "ready" : "failed");
} else {
debugPrint(WiFi.softAP(hostnameChar) ? "ready" : "failed");
}
debugPrint("Connect to Wi-Fi access point: ");
debugPrintln(hostnameChar);
delay(500); // Without delay I've seen the IP address blank
debugPrint("AP IP address: ");
debugPrintln(WiFi.softAPIP());
// dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
// dnsServer.start(DNS_PORT, "*", WiFi.softAPIP());
}
webServer.on("/wifi", HTTP_POST, []() {
String ssid = webServer.arg("ssid");
String password = webServer.arg("password");
char ssidChars[50];
ssid.toCharArray(ssidChars, 50);
char passwordChars[50];
password.toCharArray(passwordChars, 50);
debugPrint("Connecting to new SSID: ");
debugPrintln(ssid);
WiFi.begin(ssidChars, passwordChars);
webServer.sendHeader("Location", "/wifi.htm");
webServer.send(303);
});
webServer.on("/wifi", HTTP_GET, []() {
String json = getWiFiJson();
webServer.send(200, "application/json", json);
});
}

BIN
data/images/github.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

View File

@ -13,7 +13,7 @@
<!-- request CSS from the ESP8266 web server --> <!-- request CSS from the ESP8266 web server -->
<!-- <link rel="stylesheet" href="css/bootstrap.min.css"> --> <!-- <link rel="stylesheet" href="css/bootstrap.min.css"> -->
<!-- <link rel="stylesheet" href="css/jquery.minicolors.min.css"> --> <!-- <link rel="stylesheet" href="css/minicolors.min.css"> -->
<link rel="stylesheet" href="css/styles.css"> <link rel="stylesheet" href="css/styles.css">
@ -31,7 +31,7 @@
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
</button> </button>
<a class="navbar-brand" href="https://www.evilgeniuslabs.org" target="_blank"><img src="https://evilgeniuslabs.org/images/atom.svg" style="width: 24px; height: 24px;" /></a> <a class="navbar-brand" href="https://www.evilgeniuslabs.org" target="_blank"><img src="/images/atom196.png" style="width: 24px; height: 24px;" /></a>
<a class="navbar-brand" href="https://www.evilgeniuslabs.org" target="_blank">Evil Genius Labs</a> <a class="navbar-brand" href="https://www.evilgeniuslabs.org" target="_blank">Evil Genius Labs</a>
</div> </div>
<div class="collapse navbar-collapse" id="navbar-collapse-1"> <div class="collapse navbar-collapse" id="navbar-collapse-1">
@ -40,11 +40,12 @@
<li><a href="/simple.htm" target="_blank" title="Simple Mode">Simple</a></li> <li><a href="/simple.htm" target="_blank" title="Simple Mode">Simple</a></li>
<li><a href="/edit.htm" target="_blank" title="Edit Files">Files</a></li> <li><a href="/edit.htm" target="_blank" title="Edit Files">Files</a></li>
<li><a href="/update" target="_blank" title="Update Firmware">Firmware</a></li> <li><a href="/update" target="_blank" title="Update Firmware">Firmware</a></li>
<li><a href="/wifi.htm" target="_blank" title="Wi-Fi Settings">Wi-Fi</a></li>
</ul> </ul>
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<li> <li>
<a href="https://github.com/jasoncoon/esp8266-fastled-webserver"> <a href="https://github.com/jasoncoon/esp8266-fastled-webserver">
<img style="height: 16px;" src="https://assets-cdn.github.com/favicon.ico" /> <img style="height: 16px;" src="/images/github.ico" />
</a> </a>
</li> </li>
</ul> </ul>
@ -215,7 +216,7 @@
</nav> </nav>
<!-- request js from internet CDN --> <!-- request js from internet CDN -->
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script> <script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script> -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-minicolors/2.2.4/jquery.minicolors.min.js" integrity="sha256-XAFQ9dZ6hy8p/GRhU8h/8pMvM1etymiJLZW1CiHV3bQ=" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-minicolors/2.2.4/jquery.minicolors.min.js" integrity="sha256-XAFQ9dZ6hy8p/GRhU8h/8pMvM1etymiJLZW1CiHV3bQ=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/reconnecting-websocket/1.0.0/reconnecting-websocket.min.js" integrity="sha256-A4JwlcDvqO4JXpvEtvWY1RH8JAEMu5W21wP8GUXLUNs=" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/reconnecting-websocket/1.0.0/reconnecting-websocket.min.js" integrity="sha256-A4JwlcDvqO4JXpvEtvWY1RH8JAEMu5W21wP8GUXLUNs=" crossorigin="anonymous"></script>
@ -223,7 +224,7 @@
<!-- request js from the ESP8266 web server --> <!-- request js from the ESP8266 web server -->
<!-- <script src="js/jquery-3.1.1.min.js"></script> --> <!-- <script src="js/jquery-3.1.1.min.js"></script> -->
<!-- <script src="js/bootstrap.min.js"></script> --> <!-- <script src="js/bootstrap.min.js"></script> -->
<!-- <script src="js/jquery.minicolors.min.js"></script> --> <!-- <script src="js/minicolors.min.js"></script> -->
<!-- <script src="js/r-websocket.min.js"></script> --> <!-- <script src="js/r-websocket.min.js"></script> -->
<script src="js/app.js"></script> <script src="js/app.js"></script>

View File

@ -1,3 +1,8 @@
// require ./jquery-3.1.1.min.js
// require ./bootstrap.min.js
// require ./minicolors.min.js
// require ./r-websocket.min.js
// used when hosting the site on the ESP8266 // used when hosting the site on the ESP8266
var address = location.hostname; var address = location.hostname;
var urlBase = ""; var urlBase = "";

View File

@ -1,3 +1,5 @@
// require ./jquery-3.1.1.min.js
/*! /*!
* Bootstrap v3.3.7 (http://getbootstrap.com) * Bootstrap v3.3.7 (http://getbootstrap.com)
* Copyright 2011-2016 Twitter, Inc. * Copyright 2011-2016 Twitter, Inc.

View File

@ -1,3 +1,5 @@
// require ./jquery-3.1.1.min.js
/* /*
* jQuery MiniColors: A tiny color picker built on jQuery * jQuery MiniColors: A tiny color picker built on jQuery
* *

95
data/wifi.htm Normal file
View File

@ -0,0 +1,95 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ESP8266 + FastLED by Evil Genius Labs</title>
<!-- request CSS from internet CDN -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- request CSS from the ESP8266 web server -->
<!-- <link rel="stylesheet" href="css/bootstrap.min.css"> -->
<link rel="stylesheet" href="css/styles.css">
<link rel="icon" href="images/atom196.png">
</head>
<body>
<nav class="navbar navbar-default navbar-static-top" id="top" role="banner">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="https://www.evilgeniuslabs.org" target="_blank"><img src="/images/atom196.png" style="width: 24px; height: 24px;" /></a>
<a class="navbar-brand" href="https://www.evilgeniuslabs.org" target="_blank">Evil Genius Labs</a>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="/">ESP8266 + FastLED <span class="sr-only">(current)</span></a></li>
<li><a href="/simple.htm" target="_blank" title="Simple Mode">Simple</a></li>
<li><a href="/edit.htm" target="_blank" title="Edit Files">Files</a></li>
<li><a href="/update" target="_blank" title="Update Firmware">Firmware</a></li>
<li class="active"><a href="/wifi.htm" target="_blank" title="Wi-Fi Settings">Wi-Fi</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/jasoncoon/esp8266-fastled-webserver">
<img style="height: 16px;" src="/images/github.ico" />
</a>
</li>
</ul>
</div>
</div>
</nav>
<div id="container" class="container">
<form class="form-horizontal" id="form" action="/wifi" method="post">
<div class="form-group">
<label for="inputSSID" class="col-sm-2 control-label">SSID</label>
<div class="col-sm-10">
<input type="text" autocorrect="off" autocapitalize="none"
class="form-control" id="inputSSID" name="ssid" placeholder="SSID (Wi-Fi network name)">
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="inputPassword" name="password" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Connect</button>
</div>
</div>
</form>
</div>
<!-- request js from internet CDN -->
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<!-- <script src="https://unpkg.com/isotope-layout@3/dist/isotope.pkgd.min.js"></script> -->
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/reconnecting-websocket/1.0.0/reconnecting-websocket.min.js" integrity="sha256-A4JwlcDvqO4JXpvEtvWY1RH8JAEMu5W21wP8GUXLUNs=" crossorigin="anonymous"></script> -->
<!-- request js from the ESP8266 web server -->
<!-- <script src="js/jquery-3.1.1.min.js"></script> -->
<!-- <script src="js/bootstrap.min.js"></script> -->
</body>
</html>

View File

@ -1,20 +1,23 @@
/* /*
ESP8266 + FastLED + IR Remote: https://github.com/jasoncoon/esp8266-fastled-webserver * ESP8266 + FastLED + IR Remote: https://github.com/jasoncoon/esp8266-fastled-webserver
Copyright (C) 2015-2016 Jason Coon * Copyright (C) 2015-2016 Jason Coon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
This program is free software: you can redistribute it and/or modify #define FASTLED_INTERRUPT_RETRY_COUNT 1
it under the terms of the GNU General Public License as published by //#define FASTLED_ALLOW_INTERRUPTS 0
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <FastLED.h> #include <FastLED.h>
FASTLED_USING_NAMESPACE FASTLED_USING_NAMESPACE
@ -24,50 +27,38 @@ extern "C" {
} }
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <ESP8266mDNS.h> //#include <ESP8266mDNS.h>
#include <ESP8266WebServer.h> #include <ESP8266WebServer.h>
#include <ESP8266HTTPUpdateServer.h> #include <ESP8266HTTPUpdateServer.h>
#include <WebSocketsServer.h> #include <WebSocketsServer.h>
#include <FS.h> #include <FS.h>
#include <EEPROM.h> #include <EEPROM.h>
#include <IRremoteESP8266.h> //#include <IRremoteESP8266.h>
#include "GradientPalettes.h" #include "GradientPalettes.h"
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0])) #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
#include "Field.h" #include "Field.h"
#define HOSTNAME "ESP8266-" ///< Hostname. The setup function adds the Chip ID at the end. //#define RECV_PIN D4
//IRrecv irReceiver(RECV_PIN);
#define RECV_PIN 1 //#include "Commands.h"
IRrecv irReceiver(RECV_PIN);
#include "Commands.h"
const bool apMode = false;
// AP mode password
const char WiFiAPPSK[] = "";
// Wi-Fi network to connect to (if not in AP mode)
const char* ssid = "";
const char* password = "";
ESP8266WebServer webServer(80); ESP8266WebServer webServer(80);
WebSocketsServer webSocketsServer = WebSocketsServer(81); WebSocketsServer webSocketsServer = WebSocketsServer(81);
ESP8266HTTPUpdateServer httpUpdateServer; ESP8266HTTPUpdateServer httpUpdateServer;
#include "WiFi.h"
#include "FSBrowser.h" #include "FSBrowser.h"
#define DATA_PIN MOSI #define DATA_PIN D5
#define CLK_PIN SCK #define LED_TYPE WS2812
#define LED_TYPE APA102 #define COLOR_ORDER RGB
#define COLOR_ORDER BGR #define NUM_LEDS 50
#define MatrixWidth 8 * 3
#define MatrixHeight 8
#define NUM_LEDS MatrixWidth * MatrixHeight
#define MILLI_AMPS 500 // IMPORTANT: set the max milli-Amps of your power supply (4A = 4000mA) #define MILLI_AMPS 3000 // IMPORTANT: set the max milli-Amps of your power supply (4A = 4000mA)
#define FRAMES_PER_SECOND 120 // here you can control the speed. With the Access Point / Web Server the animations run a bit slower. #define FRAMES_PER_SECOND 120 // here you can control the speed. With the Access Point / Web Server the animations run a bit slower.
CRGB leds[NUM_LEDS]; CRGB leds[NUM_LEDS];
@ -109,8 +100,6 @@ CRGBPalette16 IceColors_p = CRGBPalette16(CRGB::Black, CRGB::Blue, CRGB::Aqua, C
uint8_t currentPatternIndex = 0; // Index number of which pattern is current uint8_t currentPatternIndex = 0; // Index number of which pattern is current
uint8_t autoplay = 0; uint8_t autoplay = 0;
bool resetPattern = true;
uint8_t autoplayDuration = 10; uint8_t autoplayDuration = 10;
unsigned long autoPlayTimeout = 0; unsigned long autoPlayTimeout = 0;
@ -128,30 +117,6 @@ void dimAll(byte value)
} }
} }
const bool MatrixSerpentineLayout = true;
uint16_t XY(uint8_t x, uint8_t y)
{
uint16_t i;
if ( MatrixSerpentineLayout == false) {
i = (y * MatrixWidth) + x;
}
if ( MatrixSerpentineLayout == true) {
if ( x & 0x01) {
// Odd columns run backwards
uint8_t reverseY = (MatrixHeight - 1) - y;
i = (x * MatrixHeight) + reverseY;
} else {
// Even rows run forwards
i = (x * MatrixHeight) + y;
}
}
return i;
}
typedef void (*Pattern)(); typedef void (*Pattern)();
typedef Pattern PatternList[]; typedef Pattern PatternList[];
typedef struct { typedef struct {
@ -162,17 +127,10 @@ typedef PatternAndName PatternAndNameList[];
#include "Twinkles.h" #include "Twinkles.h"
#include "TwinkleFOX.h" #include "TwinkleFOX.h"
#include "Sunrise.h"
// List of patterns to cycle through. Each is defined as a separate function below. // List of patterns to cycle through. Each is defined as a separate function below.
PatternAndNameList patterns = { PatternAndNameList patterns = {
{ sunriseStatic, "Sunrise Static" },
{ sunriseFlicker, "Sunrise Flicker" },
{ sunriseWavesVertical, "Sunrise Waves Vertical" },
{ sunriseWavesHorizontal, "Sunrise Waves Horizontal" },
{ sunriseWavesDiagonal, "Sunrise Waves Diagonal" },
{ sunriseWavesRotating, "Sunrise Waves Rotating" },
{ pride, "Pride" }, { pride, "Pride" },
{ colorWaves, "Color Waves" }, { colorWaves, "Color Waves" },
@ -216,7 +174,7 @@ const uint8_t patternCount = ARRAY_SIZE(patterns);
typedef struct { typedef struct {
CRGBPalette16 palette; CRGBPalette16 palette;
String name; String name;
} PaletteAndName; } PaletteAndName;
typedef PaletteAndName PaletteAndNameList[]; typedef PaletteAndName PaletteAndNameList[];
const CRGBPalette16 palettes[] = { const CRGBPalette16 palettes[] = {
@ -241,7 +199,7 @@ const String paletteNames[paletteCount] = {
"Forest", "Forest",
"Party", "Party",
"Heat", "Heat",
}; };
#include "Fields.h" #include "Fields.h"
@ -250,8 +208,8 @@ void setup() {
delay(100); delay(100);
Serial.setDebugOutput(true); Serial.setDebugOutput(true);
// FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS); // for WS2812 (Neopixel) FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS); // for WS2812 (Neopixel)
FastLED.addLeds<LED_TYPE, DATA_PIN, CLK_PIN, COLOR_ORDER>(leds, NUM_LEDS); // for APA102 (Dotstar) //FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS); // for APA102 (Dotstar)
FastLED.setDither(false); FastLED.setDither(false);
FastLED.setCorrection(TypicalLEDStrip); FastLED.setCorrection(TypicalLEDStrip);
FastLED.setBrightness(brightness); FastLED.setBrightness(brightness);
@ -264,7 +222,7 @@ void setup() {
FastLED.setBrightness(brightness); FastLED.setBrightness(brightness);
irReceiver.enableIRIn(); // Start the receiver // irReceiver.enableIRIn(); // Start the receiver
Serial.println(); Serial.println();
Serial.print( F("Heap: ") ); Serial.println(system_get_free_heap_size()); Serial.print( F("Heap: ") ); Serial.println(system_get_free_heap_size());
@ -288,57 +246,7 @@ void setup() {
Serial.printf("\n"); Serial.printf("\n");
} }
// Set Hostname. initializeWiFi();
String hostname(HOSTNAME);
hostname += String(ESP.getChipId(), HEX);
WiFi.hostname(hostname);
char hostnameChar[hostname.length() + 1];
memset(hostnameChar, 0, hostname.length() + 1);
for (uint8_t i = 0; i < hostname.length(); i++)
hostnameChar[i] = hostname.charAt(i);
MDNS.begin(hostnameChar);
// Add service to MDNS-SD
MDNS.addService("http", "tcp", 80);
// Print hostname.
Serial.println("Hostname: " + hostname);
if (apMode)
{
WiFi.mode(WIFI_AP);
// Do a little work to get a unique-ish name. Append the
// last two bytes of the MAC (HEX'd) to "Thing-":
uint8_t mac[WL_MAC_ADDR_LENGTH];
WiFi.softAPmacAddress(mac);
String macID = String(mac[WL_MAC_ADDR_LENGTH - 2], HEX) +
String(mac[WL_MAC_ADDR_LENGTH - 1], HEX);
macID.toUpperCase();
String AP_NameString = "ESP8266-" + macID;
char AP_NameChar[AP_NameString.length() + 1];
memset(AP_NameChar, 0, AP_NameString.length() + 1);
for (int i = 0; i < AP_NameString.length(); i++)
AP_NameChar[i] = AP_NameString.charAt(i);
WiFi.softAP(AP_NameChar, WiFiAPPSK);
Serial.printf("Connect to Wi-Fi access point: %s\n", AP_NameChar);
Serial.println("and open http://192.168.4.1 in your browser");
}
else
{
WiFi.mode(WIFI_STA);
Serial.printf("Connecting to %s\n", ssid);
if (String(WiFi.SSID()) != String(ssid)) {
WiFi.begin(ssid, password);
}
}
httpUpdateServer.setup(&webServer); httpUpdateServer.setup(&webServer);
@ -390,7 +298,7 @@ void setup() {
webServer.on("/twinkleSpeed", HTTP_POST, []() { webServer.on("/twinkleSpeed", HTTP_POST, []() {
String value = webServer.arg("value"); String value = webServer.arg("value");
twinkleSpeed = value.toInt(); twinkleSpeed = value.toInt();
if (twinkleSpeed < 0) twinkleSpeed = 0; if(twinkleSpeed < 0) twinkleSpeed = 0;
else if (twinkleSpeed > 8) twinkleSpeed = 8; else if (twinkleSpeed > 8) twinkleSpeed = 8;
broadcastInt("twinkleSpeed", twinkleSpeed); broadcastInt("twinkleSpeed", twinkleSpeed);
sendInt(twinkleSpeed); sendInt(twinkleSpeed);
@ -399,7 +307,7 @@ void setup() {
webServer.on("/twinkleDensity", HTTP_POST, []() { webServer.on("/twinkleDensity", HTTP_POST, []() {
String value = webServer.arg("value"); String value = webServer.arg("value");
twinkleDensity = value.toInt(); twinkleDensity = value.toInt();
if (twinkleDensity < 0) twinkleDensity = 0; if(twinkleDensity < 0) twinkleDensity = 0;
else if (twinkleDensity > 8) twinkleDensity = 8; else if (twinkleDensity > 8) twinkleDensity = 8;
broadcastInt("twinkleDensity", twinkleDensity); broadcastInt("twinkleDensity", twinkleDensity);
sendInt(twinkleDensity); sendInt(twinkleDensity);
@ -509,10 +417,11 @@ void loop() {
// Add entropy to random number generator; we use a lot of it. // Add entropy to random number generator; we use a lot of it.
random16_add_entropy(random(65535)); random16_add_entropy(random(65535));
// dnsServer.processNextRequest();
webSocketsServer.loop(); webSocketsServer.loop();
webServer.handleClient(); webServer.handleClient();
handleIrInput(); // handleIrInput();
if (power == 0) { if (power == 0) {
fill_solid(leds, NUM_LEDS, CRGB::Black); fill_solid(leds, NUM_LEDS, CRGB::Black);
@ -547,8 +456,6 @@ void loop() {
FastLED.show(); FastLED.show();
resetPattern = false;
// insert a delay to keep the framerate modest // insert a delay to keep the framerate modest
// FastLED.delay(1000 / FRAMES_PER_SECOND); // FastLED.delay(1000 / FRAMES_PER_SECOND);
} }
@ -590,212 +497,212 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length
} }
} }
void handleIrInput() //void handleIrInput()
{ //{
InputCommand command = readCommand(); // InputCommand command = readCommand();
//
if (command != InputCommand::None) { // if (command != InputCommand::None) {
Serial.print("command: "); // Serial.print("command: ");
Serial.println((int) command); // Serial.println((int) command);
} // }
//
switch (command) { // switch (command) {
case InputCommand::Up: { // case InputCommand::Up: {
adjustPattern(true); // adjustPattern(true);
break; // break;
} // }
case InputCommand::Down: { // case InputCommand::Down: {
adjustPattern(false); // adjustPattern(false);
break; // break;
} // }
case InputCommand::Power: { // case InputCommand::Power: {
setPower(power == 0 ? 1 : 0); // setPower(power == 0 ? 1 : 0);
break; // break;
} // }
case InputCommand::BrightnessUp: { // case InputCommand::BrightnessUp: {
adjustBrightness(true); // adjustBrightness(true);
break; // break;
} // }
case InputCommand::BrightnessDown: { // case InputCommand::BrightnessDown: {
adjustBrightness(false); // adjustBrightness(false);
break; // break;
} // }
case InputCommand::PlayMode: { // toggle pause/play // case InputCommand::PlayMode: { // toggle pause/play
setAutoplay(!autoplay); // setAutoplay(!autoplay);
break; // break;
} // }
//
// pattern buttons // // pattern buttons
//
case InputCommand::Pattern1: { // case InputCommand::Pattern1: {
setPattern(0); // setPattern(0);
break; // break;
} // }
case InputCommand::Pattern2: { // case InputCommand::Pattern2: {
setPattern(1); // setPattern(1);
break; // break;
} // }
case InputCommand::Pattern3: { // case InputCommand::Pattern3: {
setPattern(2); // setPattern(2);
break; // break;
} // }
case InputCommand::Pattern4: { // case InputCommand::Pattern4: {
setPattern(3); // setPattern(3);
break; // break;
} // }
case InputCommand::Pattern5: { // case InputCommand::Pattern5: {
setPattern(4); // setPattern(4);
break; // break;
} // }
case InputCommand::Pattern6: { // case InputCommand::Pattern6: {
setPattern(5); // setPattern(5);
break; // break;
} // }
case InputCommand::Pattern7: { // case InputCommand::Pattern7: {
setPattern(6); // setPattern(6);
break; // break;
} // }
case InputCommand::Pattern8: { // case InputCommand::Pattern8: {
setPattern(7); // setPattern(7);
break; // break;
} // }
case InputCommand::Pattern9: { // case InputCommand::Pattern9: {
setPattern(8); // setPattern(8);
break; // break;
} // }
case InputCommand::Pattern10: { // case InputCommand::Pattern10: {
setPattern(9); // setPattern(9);
break; // break;
} // }
case InputCommand::Pattern11: { // case InputCommand::Pattern11: {
setPattern(10); // setPattern(10);
break; // break;
} // }
case InputCommand::Pattern12: { // case InputCommand::Pattern12: {
setPattern(11); // setPattern(11);
break; // break;
} // }
//
// custom color adjustment buttons // // custom color adjustment buttons
//
case InputCommand::RedUp: { // case InputCommand::RedUp: {
solidColor.red += 8; // solidColor.red += 8;
setSolidColor(solidColor); // setSolidColor(solidColor);
break; // break;
} // }
case InputCommand::RedDown: { // case InputCommand::RedDown: {
solidColor.red -= 8; // solidColor.red -= 8;
setSolidColor(solidColor); // setSolidColor(solidColor);
break; // break;
} // }
case InputCommand::GreenUp: { // case InputCommand::GreenUp: {
solidColor.green += 8; // solidColor.green += 8;
setSolidColor(solidColor); // setSolidColor(solidColor);
break; // break;
} // }
case InputCommand::GreenDown: { // case InputCommand::GreenDown: {
solidColor.green -= 8; // solidColor.green -= 8;
setSolidColor(solidColor); // setSolidColor(solidColor);
break; // break;
} // }
case InputCommand::BlueUp: { // case InputCommand::BlueUp: {
solidColor.blue += 8; // solidColor.blue += 8;
setSolidColor(solidColor); // setSolidColor(solidColor);
break; // break;
} // }
case InputCommand::BlueDown: { // case InputCommand::BlueDown: {
solidColor.blue -= 8; // solidColor.blue -= 8;
setSolidColor(solidColor); // setSolidColor(solidColor);
break; // break;
} // }
//
// color buttons // // color buttons
//
case InputCommand::Red: { // case InputCommand::Red: {
setSolidColor(CRGB::Red); // setSolidColor(CRGB::Red);
break; // break;
} // }
case InputCommand::RedOrange: { // case InputCommand::RedOrange: {
setSolidColor(CRGB::OrangeRed); // setSolidColor(CRGB::OrangeRed);
break; // break;
} // }
case InputCommand::Orange: { // case InputCommand::Orange: {
setSolidColor(CRGB::Orange); // setSolidColor(CRGB::Orange);
break; // break;
} // }
case InputCommand::YellowOrange: { // case InputCommand::YellowOrange: {
setSolidColor(CRGB::Goldenrod); // setSolidColor(CRGB::Goldenrod);
break; // break;
} // }
case InputCommand::Yellow: { // case InputCommand::Yellow: {
setSolidColor(CRGB::Yellow); // setSolidColor(CRGB::Yellow);
break; // break;
} // }
//
case InputCommand::Green: { // case InputCommand::Green: {
setSolidColor(CRGB::Green); // setSolidColor(CRGB::Green);
break; // break;
} // }
case InputCommand::Lime: { // case InputCommand::Lime: {
setSolidColor(CRGB::Lime); // setSolidColor(CRGB::Lime);
break; // break;
} // }
case InputCommand::Aqua: { // case InputCommand::Aqua: {
setSolidColor(CRGB::Aqua); // setSolidColor(CRGB::Aqua);
break; // break;
} // }
case InputCommand::Teal: { // case InputCommand::Teal: {
setSolidColor(CRGB::Teal); // setSolidColor(CRGB::Teal);
break; // break;
} // }
case InputCommand::Navy: { // case InputCommand::Navy: {
setSolidColor(CRGB::Navy); // setSolidColor(CRGB::Navy);
break; // break;
} // }
//
case InputCommand::Blue: { // case InputCommand::Blue: {
setSolidColor(CRGB::Blue); // setSolidColor(CRGB::Blue);
break; // break;
} // }
case InputCommand::RoyalBlue: { // case InputCommand::RoyalBlue: {
setSolidColor(CRGB::RoyalBlue); // setSolidColor(CRGB::RoyalBlue);
break; // break;
} // }
case InputCommand::Purple: { // case InputCommand::Purple: {
setSolidColor(CRGB::Purple); // setSolidColor(CRGB::Purple);
break; // break;
} // }
case InputCommand::Indigo: { // case InputCommand::Indigo: {
setSolidColor(CRGB::Indigo); // setSolidColor(CRGB::Indigo);
break; // break;
} // }
case InputCommand::Magenta: { // case InputCommand::Magenta: {
setSolidColor(CRGB::Magenta); // setSolidColor(CRGB::Magenta);
break; // break;
} // }
//
case InputCommand::White: { // case InputCommand::White: {
setSolidColor(CRGB::White); // setSolidColor(CRGB::White);
break; // break;
} // }
case InputCommand::Pink: { // case InputCommand::Pink: {
setSolidColor(CRGB::Pink); // setSolidColor(CRGB::Pink);
break; // break;
} // }
case InputCommand::LightPink: { // case InputCommand::LightPink: {
setSolidColor(CRGB::LightPink); // setSolidColor(CRGB::LightPink);
break; // break;
} // }
case InputCommand::BabyBlue: { // case InputCommand::BabyBlue: {
setSolidColor(CRGB::CornflowerBlue); // setSolidColor(CRGB::CornflowerBlue);
break; // break;
} // }
case InputCommand::LightBlue: { // case InputCommand::LightBlue: {
setSolidColor(CRGB::LightBlue); // setSolidColor(CRGB::LightBlue);
break; // break;
} // }
} // }
} //}
void loadSettings() void loadSettings()
{ {
@ -842,7 +749,7 @@ void setPower(uint8_t value)
} }
void setAutoplay(uint8_t value) void setAutoplay(uint8_t value)
{ {
autoplay = value == 0 ? 0 : 1; autoplay = value == 0 ? 0 : 1;
EEPROM.write(6, autoplay); EEPROM.write(6, autoplay);
@ -917,14 +824,12 @@ void setPattern(uint8_t value)
} }
broadcastInt("pattern", currentPatternIndex); broadcastInt("pattern", currentPatternIndex);
resetPattern = true;
} }
void setPatternName(String name) void setPatternName(String name)
{ {
for (uint8_t i = 0; i < patternCount; i++) { for(uint8_t i = 0; i < patternCount; i++) {
if (patterns[i].name == name) { if(patterns[i].name == name) {
setPattern(i); setPattern(i);
break; break;
} }
@ -946,8 +851,8 @@ void setPalette(uint8_t value)
void setPaletteName(String name) void setPaletteName(String name)
{ {
for (uint8_t i = 0; i < paletteCount; i++) { for(uint8_t i = 0; i < paletteCount; i++) {
if (paletteNames[i] == name) { if(paletteNames[i] == name) {
setPalette(i); setPalette(i);
break; break;
} }
@ -1041,13 +946,13 @@ void sinelon()
{ {
// a colored dot sweeping back and forth, with fading trails // a colored dot sweeping back and forth, with fading trails
fadeToBlackBy( leds, NUM_LEDS, 20); fadeToBlackBy( leds, NUM_LEDS, 20);
int pos = beatsin16(speed, 0, NUM_LEDS); int pos = beatsin16(speed, 0, NUM_LEDS - 1);
static int prevpos = 0; static int prevpos = 0;
CRGB color = ColorFromPalette(palettes[currentPaletteIndex], gHue, 255); CRGB color = ColorFromPalette(palettes[currentPaletteIndex], gHue, 255);
if ( pos < prevpos ) { if( pos < prevpos ) {
fill_solid( leds + pos, (prevpos - pos) + 1, color); fill_solid( leds+pos, (prevpos-pos)+1, color);
} else { } else {
fill_solid( leds + prevpos, (pos - prevpos) + 1, color); fill_solid( leds+prevpos, (pos-prevpos)+1, color);
} }
prevpos = pos; prevpos = pos;
} }

193
sunrise.h
View File

@ -1,193 +0,0 @@
const uint16_t sunriseSeconds = 60; // how long should the "sun" take to rise from completely dark to completely lit
const uint16_t sunriseMillis = (sunriseSeconds * 1000);
const uint16_t sunriseInterval = sunriseMillis / 240; // when using palettes, the usable range is 0-240 before it starts wrapping from the last color to the first
uint8_t sunriseIncrement = 4; // how much to change brightness for each level of the matrix
uint8_t sunriseLevel;
const CRGBPalette16 sunrisePalette = HeatColors_p;
const uint8_t centerX = MatrixWidth / 2;
void updateSunrise() {
EVERY_N_MILLIS(sunriseInterval) {
if (sunriseLevel < 240) {
sunriseLevel++;
Serial.print("Current level: "); Serial.println(sunriseLevel);
}
else if (sunriseIncrement > 0) {
sunriseIncrement--;
}
}
if (resetPattern) {
sunriseLevel = 0;
sunriseIncrement = 4;
FastLED.clear();
}
}
void sunriseStatic() {
updateSunrise();
for (uint8_t x = 0; x < MatrixWidth; x++) {
int16_t d = sunriseLevel - sunriseIncrement;
for (uint8_t y = 0; y < MatrixHeight; y++) {
if (d >= 0) {
CRGB newcolor = ColorFromPalette(sunrisePalette, random(0, d), random8(d, 255));
uint16_t pixelnumber = XY(x, y);
nblend(leds[pixelnumber], newcolor, 64);
}
d -= sunriseIncrement;
}
}
}
void sunriseFlicker() {
dimAll(240);
updateSunrise();
for (uint8_t x = 0; x < MatrixWidth; x++) {
int16_t d = sunriseLevel - sunriseIncrement;
for (uint8_t y = 0; y < MatrixHeight; y++) {
if (d >= 0) {
CRGB newcolor = ColorFromPalette(sunrisePalette, random(0, d), random8(d, 255));
uint16_t pixelnumber = XY(x, y);
nblend(leds[pixelnumber], newcolor, 64);
}
d -= sunriseIncrement;
}
}
}
void sunriseWavesDiagonal() {
dimAll(240);
updateSunrise();
uint8_t t = beat8(60);
for (uint8_t x = 0; x < MatrixWidth; x++) {
for (uint8_t y = 0; y < MatrixHeight; y++) {
uint8_t cx = sin8(x);
uint8_t cy = cos8(y);
uint8_t bri8 = sin8(8 * (cx + cy) + t);
CRGB newcolor = ColorFromPalette(sunrisePalette, sunriseLevel, bri8);
uint16_t pixelnumber = XY(x, y);
pixelnumber = (NUM_LEDS - 1) - pixelnumber;
nblend(leds[pixelnumber], newcolor, 64);
}
}
}
void sunriseWavesVertical() {
updateSunrise();
static uint16_t sPseudotime = 0;
static uint16_t sLastMillis = 0;
uint8_t brightdepth = beatsin88( 341, 96, 224);
uint16_t brightnessthetainc16 = beatsin88( 203, (25 * 256), (40 * 256));
uint8_t msmultiplier = beatsin88(147, 23, 60);
uint16_t ms = millis();
uint16_t deltams = ms - sLastMillis ;
sLastMillis = ms;
sPseudotime += deltams * msmultiplier;
uint16_t brightnesstheta16 = sPseudotime;
for (uint8_t y = 0; y < MatrixHeight; y++) {
brightnesstheta16 += brightnessthetainc16;
uint16_t b16 = sin16( brightnesstheta16 ) + 32768;
uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
bri8 += (255 - brightdepth);
for (uint8_t x = 0; x < MatrixWidth; x++) {
CRGB newcolor = ColorFromPalette(sunrisePalette, sunriseLevel, bri8);
uint16_t pixelnumber = XY(x, (MatrixHeight - 1) - y);
pixelnumber = (NUM_LEDS - 1) - pixelnumber;
nblend(leds[pixelnumber], newcolor, 64);
}
}
}
void sunriseWavesHorizontal() {
updateSunrise();
static uint16_t sPseudotime = 0;
static uint16_t sLastMillis = 0;
uint8_t brightdepth = beatsin88( 341, 96, 224);
uint16_t brightnessthetainc16 = beatsin88( 203, (25 * 256), (40 * 256));
uint8_t msmultiplier = beatsin88(147, 23, 60);
uint16_t ms = millis();
uint16_t deltams = ms - sLastMillis ;
sLastMillis = ms;
sPseudotime += deltams * msmultiplier;
uint16_t brightnesstheta16 = sPseudotime;
for (uint8_t x = 0; x < MatrixWidth; x++) {
brightnesstheta16 += brightnessthetainc16;
uint16_t b16 = sin16( brightnesstheta16 ) + 32768;
uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
bri8 += (255 - brightdepth);
for (uint8_t y = 0; y < MatrixHeight; y++) {
CRGB newcolor = ColorFromPalette(sunrisePalette, sunriseLevel, bri8);
uint16_t pixelnumber = XY(x, y);
pixelnumber = (NUM_LEDS - 1) - pixelnumber;
nblend(leds[pixelnumber], newcolor, 64);
}
}
}
void sunriseWavesRotating() {
updateSunrise();
static uint16_t sPseudotime = 0;
static uint16_t sLastMillis = 0;
uint8_t brightdepth = beatsin88( 341, 96, 224);
uint16_t brightnessthetainc16 = beatsin88( 203, (25 * 256), (40 * 256));
uint8_t msmultiplier = beatsin88(147, 23, 60);
uint16_t ms = millis();
uint16_t deltams = ms - sLastMillis ;
sLastMillis = ms;
sPseudotime += deltams * msmultiplier;
uint16_t brightnesstheta16 = sPseudotime;
for (uint8_t x = 0; x < MatrixWidth; x++) {
for (uint8_t y = 0; y < MatrixHeight; y++) {
brightnesstheta16 += brightnessthetainc16;
uint16_t b16 = sin16( brightnesstheta16 ) + 32768;
uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
bri8 += (255 - brightdepth);
CRGB newcolor = ColorFromPalette(sunrisePalette, sunriseLevel, bri8);
uint16_t pixelnumber = XY(x, y);
pixelnumber = (NUM_LEDS - 1) - pixelnumber;
nblend(leds[pixelnumber], newcolor, 64);
}
}
}