Please try this: Note my "kbv" changes. You had altered your logic.
I happened to have an SSD1306 on the Uno board that I am working on.
I really don't want to dig out an ESP8266 board.
Ah-ha. While I was typing the Uno crashed. (but it might be down to the external hardware on 3. So I removed the external hardware)
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeMonoBold12pt7b.h>
#include "DHT.h"
#define DHTPIN 3 //D3 .kbv
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
int h;
int t;
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
//#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
#include "Sunnys.h" //.kbv
int frame_delay = 40; // delay for the frame
void setup() {
Serial.begin(9600);
dht.begin();
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
// Clear the buffer
display.clearDisplay();
printText();
delay(1500);
}
void loop() {
h = dht.readHumidity();
t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
h = random(60, 100); //.kbv
printText();
if (h > 80) {
showBitmap_kbv();
}
display.display(); //.kbv
delay(500); //.kbv
display.clearDisplay(); //.kbv
}
void printText() {
display.setFont(&FreeMonoBold12pt7b);
display.setTextColor(WHITE); // Draw white text
display.setCursor(75, 26); // Start at top-left corner
display.print(t);
display.drawCircle(105, 14, 3, WHITE);
display.setCursor(110, 26);
display.print("C");
display.setCursor(75, 54);
display.print(h);
display.setCursor(110, 54);
display.print("%");
display.drawRect(0, 0, 128, 64, WHITE);
}
void showBitmap_kbv(void) {
const uint8_t *Frames[] = {
Sunny1, Sunny2, Sunny3, Sunny4, Sunny5, Sunny6, Sunny7, Sunny8, Sunny9, Sunny10, Sunny11, Sunny12, Sunny13, Sunny14, Sunny15,
//Sunny16, Sunny17, Sunny18, Sunny19, Sunny20, Sunny21, Sunny22, Sunny23, Sunny24, Sunny25, Sunny26, Sunny27, Sunny28, Sunny29, Sunny30,
//Sunny31, Sunny32, Sunny33, Sunny34, Sunny35, Sunny36, Sunny37, Sunny38, Sunny39, Sunny40, Sunny41, Sunny42, Sunny43, Sunny44, Sunny45,
//Sunny46, Sunny47, Sunny48, Sunny49, Sunny50, Sunny51, Sunny52, Sunny53, Sunny54, Sunny55, Sunny56, Sunny57, Sunny58, Sunny59, Sunny60
};
for (int i = 0; i < 15; i++) {
display.drawBitmap(1, 1, Frames[i], 72, 62, WHITE); //draw the image
display.display();
delay(frame_delay); //delay
}
}
Edit.
Tried it with an SSD1309 and ESP8266 board. With :
...
t = random(10, 40); //.kbv
h = random(60, 100); //.kbv
...
void showBitmap_kbv(void) {
const uint8_t *Frames[] = {
Sunny1, Sunny2, Sunny3, Sunny4, Sunny5, Sunny6, Sunny7, Sunny8, Sunny9, Sunny10, Sunny11, Sunny12, Sunny13, Sunny14, Sunny15,
Sunny16, Sunny17, Sunny18, Sunny19, Sunny20, Sunny21, Sunny22, Sunny23, Sunny24, Sunny25, Sunny26, Sunny27, Sunny28, Sunny29, Sunny30,
Sunny31, Sunny32, Sunny33, Sunny34, Sunny35, Sunny36, Sunny37, Sunny38, Sunny39, Sunny40, Sunny41, Sunny42, Sunny43, Sunny44, Sunny45,
Sunny46, Sunny47, Sunny48, Sunny49, Sunny50, Sunny51, Sunny52, Sunny53, Sunny54, Sunny55, Sunny56, Sunny57, Sunny58, Sunny59, Sunny60
};
for (int i = 0; i < 60; i++) {
display.drawBitmap(1, 1, Frames[i], 72, 62, WHITE); //draw the image
display.display();
delay(frame_delay); //delay
}
}
The animation works fine. I strongly recommend that you move your bitmap data into a separate "Sunnys.h" sketch tab.