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
+4 -16
View File
@@ -20,24 +20,12 @@ const char index_html[] PROGMEM = R"rawliteral(
</head>
<body>
<h1>LED Panel Control</h1>
<input type="file" id="imageFile" accept=".json">
<button class="button" onclick="uploadImage()">Upload Image</button>
<button class="button" onclick="showPixels()">Show Pixels</button>
<script>
function uploadImage() {
var file = document.getElementById('imageFile').files[0];
if (!file) {
alert("Please select a file!");
return;
}
var reader = new FileReader();
reader.onload = function(e) {
var contents = e.target.result;
function showPixels() {
var xhr = new XMLHttpRequest();
xhr.open("POST", "/upload", true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(contents);
};
reader.readAsText(file);
xhr.open("GET", "/show", true);
xhr.send();
}
</script>
</body>
+15 -8
View File
@@ -1,4 +1,12 @@
#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__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
@@ -17,8 +25,8 @@ struct Pixel
uint32_t color;
};
const short saved_images_count = 1;
Pixel saved_imaged[saved_images_count][16][16] = {
// dont change this
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}
@@ -85,11 +93,7 @@ Pixel getPixelFromSaved(unsigned char i, int row, int col)
return saved_imaged[i][row][col];
}
void drawPanelImage(int offset_x, int offset_y, unsigned char i) {
if (i >= saved_images_count) {
return;
}
void drawImageFromArr(int offset_x, int offset_y, unsigned char i) {
for (int row = 0; row < 16; row++) {
for (int col = 0; col < 16; col++) {
Pixel px = getPixelFromSaved(i, row, col);
@@ -109,11 +113,14 @@ void drawPanelImage(int offset_x, int offset_y, unsigned char i) {
}
void setup() {
Serial.begin(115200);
pixels.begin();
pixels.clear();
pixels.show();
drawImageFromArr(0, 0, 0);
start_server();
}
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();
}