show image0 button

This commit is contained in:
2026-01-26 11:45:11 +01:00
parent 665c68e041
commit 81026eae48
3 changed files with 54 additions and 27 deletions
+6 -18
View File
@@ -20,26 +20,14 @@ const char index_html[] PROGMEM = R"rawliteral(
</head> </head>
<body> <body>
<h1>LED Panel Control</h1> <h1>LED Panel Control</h1>
<input type="file" id="imageFile" accept=".json"> <button class="button" onclick="showPixels()">Show Pixels</button>
<button class="button" onclick="uploadImage()">Upload Image</button>
<script> <script>
function uploadImage() { function showPixels() {
var file = document.getElementById('imageFile').files[0]; var xhr = new XMLHttpRequest();
if (!file) { xhr.open("GET", "/show", true);
alert("Please select a file!"); xhr.send();
return;
}
var reader = new FileReader();
reader.onload = function(e) {
var contents = e.target.result;
var xhr = new XMLHttpRequest();
xhr.open("POST", "/upload", true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(contents);
};
reader.readAsText(file);
} }
</script> </script>
</body> </body>
</html> </html>
)rawliteral"; )rawliteral";
+16 -9
View File
@@ -1,4 +1,12 @@
#include <Adafruit_NeoPixel.h> #include <Adafruit_NeoPixel.h>
#include <WiFi.h>
#include <WebServer.h>
#include "index.h"
// For ESP8266, you would use:
// #include <ESP8266WiFi.h>
// #include <ESP8266WebServer.h>
#ifdef __AVR__ #ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif #endif
@@ -17,8 +25,8 @@ struct Pixel
uint32_t color; uint32_t color;
}; };
const short saved_images_count = 1; // dont change this
Pixel saved_imaged[saved_images_count][16][16] = { Pixel saved_imaged[12][16][16] = {
{ {
{ {
{0, 0, 0xFF000000}, {1, 0, 0xFF000000}, {2, 0, 0xFF000000}, {3, 0, 0xFF000000}, {4, 0, 0xFF000000}, {5, 0, 0xFF000000}, {6, 0, 0xFF000000}, {7, 0, 0xFF000000}, {8, 0, 0xFF000000}, {9, 0, 0xFF000000}, {10, 0, 0xFF000000}, {11, 0, 0xFF000000}, {12, 0, 0xFF000000}, {13, 0, 0xFF000000}, {14, 0, 0xFF000000}, {15, 0, 0xFF000000} {0, 0, 0xFF000000}, {1, 0, 0xFF000000}, {2, 0, 0xFF000000}, {3, 0, 0xFF000000}, {4, 0, 0xFF000000}, {5, 0, 0xFF000000}, {6, 0, 0xFF000000}, {7, 0, 0xFF000000}, {8, 0, 0xFF000000}, {9, 0, 0xFF000000}, {10, 0, 0xFF000000}, {11, 0, 0xFF000000}, {12, 0, 0xFF000000}, {13, 0, 0xFF000000}, {14, 0, 0xFF000000}, {15, 0, 0xFF000000}
@@ -85,11 +93,7 @@ Pixel getPixelFromSaved(unsigned char i, int row, int col)
return saved_imaged[i][row][col]; return saved_imaged[i][row][col];
} }
void drawPanelImage(int offset_x, int offset_y, unsigned char i) { void drawImageFromArr(int offset_x, int offset_y, unsigned char i) {
if (i >= saved_images_count) {
return;
}
for (int row = 0; row < 16; row++) { for (int row = 0; row < 16; row++) {
for (int col = 0; col < 16; col++) { for (int col = 0; col < 16; col++) {
Pixel px = getPixelFromSaved(i, row, col); Pixel px = getPixelFromSaved(i, row, col);
@@ -109,11 +113,14 @@ void drawPanelImage(int offset_x, int offset_y, unsigned char i) {
} }
void setup() { void setup() {
pixels.begin(); Serial.begin(115200);
pixels.begin();
pixels.clear(); pixels.clear();
pixels.show(); pixels.show();
drawImageFromArr(0, 0, 0);
start_server();
} }
void loop() { void loop() {
handle_server();
} }
+32
View File
@@ -0,0 +1,32 @@
const char* ssid = "PPIA";
const char* password = "pawelpdaldonejta";
WebServer server(80);
void handleRoot() {
server.send(200, "text/html", index_html);
}
void handleShow() {
pixels.show();
drawImageFromArr(0, 0, 0);
server.send(200, "text/plain", "OK");
}
void start_server() {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
Serial.println(WiFi.localIP());
server.on("/", handleRoot);
server.on("/show", handleShow);
server.begin();
}
void handle_server() {
server.handleClient();
}