Hey guys,
So I am very new to coding. I have never posted because I am a firm believer in research research and when you are sure the answer isn't there, research some more. I have looked for the answer to this questions, and no dice, probably due to how specific it is related to the code. So I am asking you now.
There is an example sketch by AdaFruit under the ImageReader Library. It is called BreakoutST7735-128x128. I am also using the St7735 1.44 TFT screen by Adafruit with the built in sd breakout. So this example is showing you how to pull an image from the sd card, and display it to the screen. This code is written in the void setup portion of the sketch:
Serial.print(F("Loading wales.bmp to canvas..."));
stat = reader.loadBMP("/wales.bmp", img);
reader.printStatus(stat); // How'd we do?
Then in the void loop it is written like this, (there actually is more code and it's more involved and loads 4 images and rotates them, but that function is not related to my question, so I removed the function for simplicity's sake)
void loop() {
reader.drawBMP("/miniwoof.bmp", tft,
}
So I in turn, played with the code and I wrote 2 versions of the code. One that really doesn't help me because as it is in the void setup and not in the void loop, and another that is in the void loop, but is coded differently by dropping some verbage from the previous code. Now here is the point.
The fist code I wrote, it loads flawlessly, there is no "progressive scan" appearance, where it looks like it loads line by line. It is just there, instantaneous. No visual que that the screen is changing. That code is this:
void setup(void) {
ImageReturnCode stat; // Status from image-reading functions
Serial.begin(9600);
#if !defined(ESP32)
while(!Serial); // Wait for Serial Monitor before continuing
#endif
tft.initR(INITR_144GREENTAB); // Initialize screen
// The Adafruit_ImageReader constructor call (above, before setup())
// accepts an uninitialized SdFat or FatFileSystem object. This MUST
// BE INITIALIZED before using any of the image reader functions!
Serial.print(F("Initializing filesystem..."));
#if defined(USE_SD_CARD)
// SD card is pretty straightforward, a single call...
if(!SD.begin(SD_CS, SD_SCK_MHZ(10))) { // Breakouts require 10 MHz limit due to longer wires
Serial.println(F("SD begin() failed"));
for(;;); // Fatal error, do not continue
}
#else
// SPI or QSPI flash requires two steps, one to access the bare flash
// memory itself, then the second to access the filesystem within...
if(!flash.begin()) {
Serial.println(F("flash begin() failed"));
for(;;);
}
if(!filesys.begin(&flash)) {
Serial.println(F("filesys begin() failed"));
for(;;);
}
#endif
Serial.println(F("OK!"));
tft.fillScreen(ST77XX_BLACK);
stat = reader.drawBMP("/1234567AA.bmp", tft, 0, 0);delay(375);
stat = reader.drawBMP("/1234567BB.bmp", tft, 0, 0);delay(375);
stat = reader.drawBMP("/1234567CC.bmp", tft, 0, 0);delay(375);
stat = reader.drawBMP("/1234567DD.bmp", tft, 0, 0);delay(375);
stat = reader.drawBMP("/1234567EE.bmp", tft, 0, 0);delay(375);
stat = reader.drawBMP("/1234567FF.bmp", tft, 0, 0);delay(375);
stat = reader.drawBMP("/1234567GG.bmp", tft, 0, 0);delay(375);
stat = reader.drawBMP("/1234567HH.bmp", tft, 0, 0);delay(375);
stat = reader.drawBMP("/1234567II.bmp", tft, 0, 0);delay(375);
}
void loop() {
}
The way it loads them is visually outstanding. It's worth noting that every time the voltage changes, it's actually rendering a whole new bitmap, and you cant see a shutter.
The other code I have been working with is the "progressive scan" type, so because I was getting that effect, loaded a background image and I only display text to the screen. I still have a few backgorund images getting loaded where that scan effect is happening, and I also get this blink effect on the text. I tried to do an overwrite command but i am literally out of space in my sketch and I couldnt fit it in if I wanted. Here is how I am displaying those images:
void printFanPMW() {
if (showimg == true)
{
tft.fillScreen(ST77XX_BLACK);
// reader.drawBMP("fan.bmp", tft,0, 0);
showimg = false;
}
tft.setFont(&FreeMonoOblique18pt7b);
tft.setCursor(38, 70);
tft.setTextColor(ST7735_WHITE, ST7735_BLACK); // Set color of text. First is the color of text and after is color of background
tft.setTextSize(0); // Set text size. Goes from 0 (the smallest) to 20 (very big)
reader.drawBMP("/fan.bmp", tft, 0, 0);
tft.println(map(pwmDuty, 1, 255, 1, 100)); // Print a text or value
tft.setFont();
}
So the meat of my question is why does using the
stat = reader.drawBMP("/1234567VV.bmp", tft, 0, 0); (located in void setup)
load and display/render so much better than the
reader.drawBMP("/fan.bmp", tft, 0, 0); (located in the void loop)
I am sorry for such the long winded narrative to explain my question, but I didnt want to leave out any of the bits so that you got my drift so to speak. I have also included a short video file so you can see what exactly I am talking about. I am not really looking for help revising the code, I am looking to understand why the code is acting this way.
Well Thanks in advance for the knowledge!
-Spain