Smart Poi 3.0.0
WiFi Connected LED POV Poi
Loading...
Searching...
No Matches
showLittleFSImage.ino File Reference

Functions

void showLittleFSImage ()
 

Variables

int cnti = 0
 Displays an image stored on the ESP8266 using the LittleFS file system.
 

Function Documentation

◆ showLittleFSImage()

void showLittleFSImage ( )
23{
24 // Open the image file from LittleFS
25 a = LittleFS.open(bin, "r"); // Open every time?
26
27 if (!a)
28 {
29 // If no file is found, go to the next image
30 imageToUse++;
31 // FastLED.showColor(CRGB::Blue); // Display error color (optional)
32 // Serial.println("Code Blue - no file found!");
33 }
34 else
35 {
36 size_t size = a.size(); // Get file size
37
38 // Check if the image size is larger than the max allowed
39 if (size > maxPX)
40 {
41 // Display error if the image is too large
42 FastLED.showColor(CRGB::Blue); // Show blue color as error indicator
43 imageToUse++;
44 }
45 else
46 {
47 // Calculate the number of pixels across based on the file size
48 pxAcross = int(size / pxDown); // Should be an integer
49
50 // Read image data into message1Data buffer
51 a.read(message1Data, size);
52
53 cnti++;
54 if (cnti >= pxDown)
55 {
56 cnti = 0;
57 }
58
59 // Close the file after reading
60 a.close();
61 }
62 }
63
64 // Initialize counter for reading pixel data
65 int counter = 0;
66
67 // Loop through the pixels to display the image
68 for (int j = 0; j < pxAcross; j++)
69 {
70 for (int i = 0; i < pxDown; i++)
71 {
72 byte X = message1Data[counter++]; // Get pixel data
73
74 // Decompress and assign color values
75 byte R1 = (X & 0xE0); // Extract Red value (3 bits)
76 leds[i].r = R1;
77 byte G1 = ((X << 3) & 0xE0); // Extract Green value (3 bits)
78 leds[i].g = G1;
79 byte M1 = (X << 6); // Extract Blue value (2 bits)
80 leds[i].b = M1;
81
82 // Optional: Print RGB values for debugging
83 // Serial.print(R1); Serial.print(", "); Serial.print(G1); Serial.print(", "); Serial.println(M1);
84 }
85
86 // Display the current row of pixels on the LED strip
87 FastLED.show();
88
89 // Optional delay depending on the number of LEDs
90 if (NUM_LEDS < 72)
91 {
92 // FastLED.delay(1); // For 160MHz clock - only applies to APA102 Strip
93 }
94 else
95 {
96 // No delay needed for larger LED strips
97 }
98 }
99}
String bin
Definition main.ino:178
volatile byte X
Definition main.ino:240
#define NUM_LEDS
Definition main.ino:57
volatile byte R1
Definition main.ino:242
CRGB leds[121]
Definition main.ino:60
File a
Definition main.ino:44
volatile byte M1
Definition main.ino:244
int imageToUse
Definition main.ino:172
int pxDown
Definition main.ino:75
uint8_t message1Data[maxPX]
Definition main.ino:73
volatile byte G1
Definition main.ino:243
const int maxPX
Definition main.ino:67
int pxAcross
Definition main.ino:77
int cnti
Displays an image stored on the ESP8266 using the LittleFS file system.
Definition showLittleFSImage.ino:20

References a, bin, cnti, G1, imageToUse, leds, M1, maxPX, message1Data, NUM_LEDS, pxAcross, pxDown, R1, and X.

Referenced by loop().

Here is the caller graph for this function:

Variable Documentation

◆ cnti

int cnti = 0

Displays an image stored on the ESP8266 using the LittleFS file system.

This function loads an image from the LittleFS file system, checks its size, and displays the image pixel-by-pixel on an LED strip using FastLED. The image is stored in a compressed format and is decompressed into RGB values.

The function handles different cases such as missing files and oversized images. It iterates through the pixels to display the image across the LED strip.

Note
The image file should be stored in LittleFS as a binary file.
Todo
Add converter from "bin" to filename from listDir() or implement image index to access the correct image.
Todo
Test if this version can work concurrently with older image display logic.
Returns
void

Referenced by showLittleFSImage().