// REQUIRES the following Arduino libraries:
// - Lien vidéo: https://youtu.be/srP7C-sVUhk
// - Adafruit_NeoPixel: https://github.com/adafruit/Adafruit_NeoPixel
// - Adafruit_GFX Library: https://github.com/adafruit/Adafruit-GFX-Library
// - Getting Started ESP32 / ESP32S : https://www.youtube.com/watch?v=9b0Txt-yF7E
// Find All "Great Projects" Videos : https://www.youtube.com/c/GreatProjects
#include "SPIFFS.h"
#include <EEPROM.h>
#include <WiFi.h>
#include <WebServer.h>
#include <Adafruit_NeoPixel.h>
#include <Adafruit_GFX.h>
#include "atawi8c.h"
#define PIN 15
#define NUMPIXELS 512
#define EEPROM_SIZE 5
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
WebServer server(80);
GFXcanvas1 canvasF(64, 8);
char ssid[30] = "";
char pass[30] = "";
const char* Apssid = "NeoPixel";
const char* Appassword = "3tawi-GP";
IPAddress ip(192,168,1,142);
IPAddress dns(192, 168,1,1);
IPAddress gateway(192, 168,1,1);
IPAddress gatewayap(192,168,4,1);
IPAddress subnet(255, 255, 255, 0);
File myfile;
String Message = "Great Projects wish you a very nice day. Hope you have a great time ahead.";
long savednum = 0 ,passnum = 0;
int xps=32, msg = 1;
uint32_t lastTime, lastdoT, lastblack;
String text, textmsg, textip;
int sp0, sp1, sp2, sp3, sp4, sp5, sp6, sp7;
long hueShift;
long value;
int dx1, dx2, dx3, dx4, dy1, dy2, dy3, dy4, sx1, sx2, sx3, sx4;
int r, g, b;
uint8_t sat, val, lo;
float rs1, rs2, rs3, rs4,
cx1, cx2, cx3, cx4,
cy1, cy2, cy3, cy4;
float ag1, ag2, ag3, ag4;
static const int8_t PROGMEM sinetab[256] = {
0, 2, 5, 8, 11, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45,
48, 51, 54, 56, 59, 62, 65, 67, 70, 72, 75, 77, 80, 82, 85, 87,
89, 91, 93, 96, 98, 100, 101, 103, 105, 107, 108, 110, 111, 113, 114, 116,
117, 118, 119, 120, 121, 122, 123, 123, 124, 125, 125, 126, 126, 126, 126, 126,
127, 126, 126, 126, 126, 126, 125, 125, 124, 123, 123, 122, 121, 120, 119, 118,
117, 116, 114, 113, 111, 110, 108, 107, 105, 103, 101, 100, 98, 96, 93, 91,
89, 87, 85, 82, 80, 77, 75, 72, 70, 67, 65, 62, 59, 56, 54, 51,
48, 45, 42, 39, 36, 33, 30, 27, 24, 21, 18, 15, 11, 8, 5, 2,
0, -3, -6, -9, -12, -16, -19, -22, -25, -28, -31, -34, -37, -40, -43, -46,
-49, -52, -55, -57, -60, -63, -66, -68, -71, -73, -76, -78, -81, -83, -86, -88,
-90, -92, -94, -97, -99,-101,-102,-104, -106,-108,-109,-111,-112,-114,-115,-117,
-118,-119,-120,-121,-122,-123,-124,-124, -125,-126,-126,-127,-127,-127,-127,-127,
-128,-127,-127,-127,-127,-127,-126,-126, -125,-124,-124,-123,-122,-121,-120,-119,
-118,-117,-115,-114,-112,-111,-109,-108, -106,-104,-102,-101, -99, -97, -94, -92,
-90, -88, -86, -83, -81, -78, -76, -73, -71, -68, -66, -63, -60, -57, -55, -52,
-49, -46, -43, -40, -37, -34, -31, -28, -25, -22, -19, -16, -12, -9, -6, -3
};
void(* resetFunc) (void) = 0;//declare reset function at address 0
void getWifi()
{
if (WiFi.status() == WL_CONNECTED) {
WiFi.disconnect();
}
WiFi.config(ip, dns, gateway, subnet);
WiFi.begin(ssid, pass);
int xc = 0;
while (WiFi.status() != WL_CONNECTED && xc < 10) {
delay(300);
xc++;
}
if (WiFi.status() != WL_CONNECTED) {
WiFi.softAPConfig(ip, gatewayap, subnet);
WiFi.softAP(Apssid, Appassword);
textip = "Ssid or password is incorrect";
textip += " Ssid: 'ESP32VGA' Password: 'Great-Projects' IP: 'http://192.168.1.141'";
} else {
WiFi.softAPdisconnect(true);
textip = "CONNECTED To: ";
textip += ssid;
textip += " IP Address: http://";
textip += WiFi.localIP().toString().c_str();
}
msg = 1, getmesg();
}
void Colorplat(int cpla) {
switch (cpla) {
case 0:
rs1 = 4.1, rs2 = 6.3, rs3 = 10.2, rs4 = 11.1;
cx1 = 4.1, cy1 = 2.2;
cx2 = 5.8, cy2 = 1.7;
cx3 = 5.8, cy3 = 3.5;
cx4 = 1.1, cy4 = -1.5;
sp4 = 3, sp5 = 2;
break;
case 1:
rs1 = 4.1, rs2 = 6.3, rs3 = 10.2, rs4 = 11.1;
cx1 = 4.1, cy1 = 2.2;
cx2 = 5.8, cy2 = 1.7;
cx3 = 5.8, cy3 = 3.5;
cx4 = 1.1, cy4 = -1.5;
sp4 = 1, sp5 = 2;
break;
case 2:
rs1 = 4.1, rs2 = 6.3, rs3 = 10.2, rs4 = 11.1;
cx1 = 4.1, cy1 = 2.2;
cx2 = 5.8, cy2 = 1.7;
cx3 = 5.8, cy3 = 3.5;
cx4 = 1.1, cy4 = -1.5;
sp4 = 2, sp5 = 3;
break;
case 3:
rs1 = 8.1, rs2 = 8.5, rs3 = 15.4, rs4 = 17.1;
cx1 = 8.1, cy1 = 4.3;
cx2 = 5.8, cy2 = 3.3;
cx3 = 11.7, cy3 = 7.0;
cx4 = 2.1, cy4 = -1.5;
sp4 = 2, sp5 = 3;
break;
case 4:
rs1 = 12.1, rs2 = 12.5, rs3 = 20.4, rs4 = 22.1;
cx1 = 12.1, cy1 = 6.3;
cx2 = 8.8, cy2 = 4.8;
cx3 = 16.9, cy3 = 10.5;
cx4 = 3.1, cy4 = -2.1;
sp4 = 2, sp5 = 3;
break;
case 5:
rs1 = 16.3, rs2 = 23.0, rs3 = 40.8, rs4 = 44.2;
cx1 = 16.1, cy1 = 8.7;
cx2 = 11.6, cy2 = 6.5;
cx3 = 23.4, cy3 = 14.0;
cx4 = 4.1, cy4 = -2.9;
sp4 = 2, sp5 = 3;
break;
case 6:
rs1 = 24.6, rs2 = 34.5, rs3 = 15.4, rs4 = 66.4;
cx1 = 34.2, cy1 = 23.4;
cx2 = 35.2, cy2 = 19.9;
cx3 = 33.8, cy3 = 42.0;
cx4 = 12.2, cy4 = -5.6;
sp4 = 2, sp5 = 3;
break;
case 7:
rs1 = 32.6, rs2 = 46.0, rs3 = 20.4, rs4 = 88.4;
cx1 = 32.2, cy1 = 17.4;
cx2 = 23.2, cy2 = 13.0;
cx3 = 23.4, cy3 = 28.0;
cx4 = 8.2, cy4 = -5.6;
sp4 = 2, sp5 = 3;
break;
case 8:
rs1 = 65.2, rs2 = 92.0, rs3 = 40.8, rs4 = 176.8;
cx1 = 64.4, cy1 = 34.8;
cx2 = 46.4, cy2 = 26.0;
cx3 = 46.8, cy3 = 56.0;
cx4 = 16.4, cy4 = -11.2;
sp4 = 2, sp5 = 3;
break;
case 9:
rs1 = 97.8, rs2 = 138.0, rs3 = 61.2, rs4 = 265.2;
cx1 = 96.6, cy1 = 52.2;
cx2 = 69.6, cy2 = 39.0;
cx3 = 70.2, cy3 = 84.0;
cx4 = 24.6, cy4 = -16.8;
sp4 = 2, sp5 = 3;
break;
case 10:
rs1 = 130.4, rs2 = 184.0, rs3 = 81.6, rs4 = 353.6;
cx1 = 128.8, cy1 = 69.6;
cx2 = 92.8, cy2 = 52.0;
cx3 = 93.6, cy3 = 112.0;
cx4 = 32.8, cy4 = -22.4;
sp4 = 3, sp5 = 4;
break;
default:
rs1 = 130.4, rs2 = 184.0, rs3 = 81.6, rs4 = 353.6;
cx1 = 128.8, cy1 = 69.6;
cx2 = 92.8, cy2 = 52.0;
cx3 = 93.6, cy3 = 112.0;
cx4 = 32.8, cy4 = -22.4;
sp4 = 5, sp5 = 6;
break;
}
}
void getColor(long hue) {
// Hue
hue %= 1791; // -1791 to +1791
if (hue < 0)
hue += 1791; // 0 to +1791
lo = hue & 255; // Low byte = primary/secondary color mix
switch (hue >> 8) { // High byte = sextant of colorwheel
case 0:
r = 255;
g = 255 - lo;
b = 255 - lo;
break; // W to R
case 1:
r = 255;
g = lo;
b = 0;
break; // R to Y
case 2:
r = 255 - lo;
g = 255;
b = 0;
break; // Y to G
case 3:
r = 0;
g = 255;
b = lo;
break; // G to C
case 4:
r = 0;
g = 255 - lo;
b = 255;
break; // C to B
case 5:
r = lo;
g = 0;
b = 255;
break; // B to M
default:
r = 255;
g = lo;
b = 255;
break; // M to W
}
}
void getmesg()
{
xps = 32;
switch(msg)
{
case 0 :
textmsg = Message;
msg = 0;
break;
case 1 :
textmsg = textip;
msg = 0;
break;
}
}
void getdata() {
ag1 += 0.03;
ag2 -= 0.07;
ag3 += 0.13;
ag4 -= 0.15;
hueShift += 2;
}
void getblat() {
// Adjust pixel coordinates based on the 8x64 matrix layout
sx1 = (int)(cos(ag1) * rs1 + cx1);
sx2 = (int)(cos(ag2) * rs2 + cx2);
sx3 = (int)(cos(ag3) * rs3 + cx3);
sx4 = (int)(cos(ag4) * rs4 + cx4);
dy1 = (int)(sin(ag1) * rs1 + cy1);
dy2 = (int)(sin(ag2) * rs2 + cy2);
dy3 = (int)(sin(ag3) * rs3 + cy3);
dy4 = (int)(sin(ag4) * rs4 + cy4);
hueShift = xps * 10;
for (int y = 0; y < 8; y++) {
dx1 = sx1; dx2 = sx2; dx3 = sx3; dx4 = sx4;
for (int x = 0; x < 64; x++) { // Adjusted for 8x64 matrix
int xl = 504 + y - (x * 8);
int c0 = canvasF.getPixel(x, y);
if (c0 != 0) {
value = hueShift
+ (int8_t)pgm_read_byte(sinetab + (uint8_t)((dx1 * dx1 + dy1 * dy1) >> sp4))
+ (int8_t)pgm_read_byte(sinetab + (uint8_t)((dx2 * dx2 + dy2 * dy2) >> sp4))
+ (int8_t)pgm_read_byte(sinetab + (uint8_t)((dx3 * dx3 + dy3 * dy3) >> sp5))
+ (int8_t)pgm_read_byte(sinetab + (uint8_t)((dx4 * dx4 + dy4 * dy4) >> sp5));
getColor(value * 3);
pixels.setPixelColor(xl, pixels.Color(r, g, b));
} else {
pixels.setPixelColor(xl, pixels.Color(0, 0, 0));
}
dx1--; dx2--; dx3--; dx4--;
}
dy1--; dy2--; dy3--; dy4--;
}
pixels.show();
}
void scroll_text(String txt) {
uint16_t text_length = txt.length() * 7;
canvasF.fillScreen(0);
canvasF.setFont(&atawi8c);
canvasF.setCursor(xps, 0);
canvasF.print(txt);
canvasF.setFont();
xps--;
if (xps < -text_length) {getmesg();}
}
void handleRoot() {
File file = SPIFFS.open("/setting1.html");
if (file) {
size_t sent = server.streamFile(file, "text/html"); //Send web page
}
file.close();
}
void handleRestesp() {
handleRoot();
delay(4000);
resetFunc();
}
void handleSpe0() {
handleRoot();
sp0 = server.arg("Speed0").toInt();
EEPROM.write(1, sp0);
EEPROM.commit();
}
void handleSpe1() {
handleRoot();
sp1 = server.arg("Speed1").toInt();
EEPROM.write(2, sp1);
EEPROM.commit();
}
void handleMode() {
handleRoot();
sp2 = server.arg("Mode0").toInt();
EEPROM.write(3, sp2);
EEPROM.commit();
Colorplat(sp2);
}
void handleBright() {
handleRoot();
sp3 = server.arg("Bright").toInt();
EEPROM.write(4, sp3);
EEPROM.commit();
pixels.setBrightness(sp3);
}
void handleSpe4() {
handleRoot();
sp4 = server.arg("Speed4").toInt();
}
void handleSpe5() {
handleRoot();
sp5 = server.arg("Speed5").toInt();
}
void handleMesg() {
handleRoot();
Message = server.arg("Message");
myfile = SPIFFS.open("/Message.txt", FILE_WRITE);
if(myfile){
myfile.print(Message);
}
myfile.close();
msg = 0, getmesg();
}
void handleWifi() {
handleRoot();
text = server.arg("usname");
myfile = SPIFFS.open("/Ssid.txt", FILE_WRITE);
if(myfile){
myfile.print(text);
}
myfile.close();
int len = text.length() + 1;
text.toCharArray(ssid, len);
text = server.arg("pssw");
myfile = SPIFFS.open("/Password.txt", FILE_WRITE);
if(myfile){
myfile.print(text);
}
myfile.close();
len = text.length() + 1;
text.toCharArray(pass, len);
getWifi();
}
void getssid() {
myfile = SPIFFS.open("/Ssid.txt");
if(!myfile){
return;
}
int nb = 0;
while (myfile.available()) {
savednum = myfile.read();
ssid[nb] = (char) savednum;
nb += 1;
}
myfile.close();
}
void getpass() {
myfile = SPIFFS.open("/Password.txt");
if(!myfile){
return;
}
int nb = 0;
while (myfile.available()) {
savednum = myfile.read();
pass[nb] = (char) savednum;
nb += 1;
}
myfile.close();
}
void getstting() {
sp0 = EEPROM.read(1);
sp1 = EEPROM.read(2);
sp2 = EEPROM.read(3);
sp3 = EEPROM.read(4);
myfile = SPIFFS.open("/Message.txt");
if(!myfile){
return;
}
Message = "";
while (myfile.available()) {
savednum = myfile.read();
Message += (char)savednum;
}
myfile.close();
}
void setup() {
SPIFFS.begin(true);
EEPROM.begin(EEPROM_SIZE);
pixels.begin();
canvasF.setTextWrap(false);
getssid();
getpass();
getWifi();
server.on("/", handleRoot);
server.on("/MesBright", handleBright);
server.on("/MesMode", handleMode);
server.on("/MesSpeed0", handleSpe0);
server.on("/MesSpeed1", handleSpe1);
server.on("/MesSpeed4", handleSpe4);
server.on("/MesSpeed5", handleSpe5);
server.on("/myMesg", handleMesg);
server.on("/Mywifi", handleWifi);
server.on("/restesp", handleRestesp);
server.begin();
getstting();
Colorplat(sp2);
pixels.setBrightness(sp3);
pixels.show();
delay(2000);
}
void loop() {
server.handleClient();
if(millis() - lastTime >= sp0) {
scroll_text(textmsg);
getblat();
lastTime = millis();
}
if(millis() - lastdoT >= sp1) {
getdata();
lastdoT = millis();
}
}