#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "images.h"
#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)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
int previousImageIndex = 1;
int helloWorldScreen = 0;
int currentImageIndex = 1;
void setup() {
Serial.begin(115200);
// Initialize the OLED display
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
delay(2000); // Pause to let screen boot and all of that
display.clearDisplay();
// Draw HelloWorld on the screen
display.drawBitmap(0, 0, epd_bitmap_allArray[helloWorldScreen], 128, 64, 1);
display.display();
delay(2000);
display.clearDisplay();
}
void loop() {
currentImageIndex = getRandomInRange(epd_bitmap_allArray_LEN);
if (currentImageIndex == previousImageIndex) {
currentImageIndex = getRandomInRange(epd_bitmap_allArray_LEN);
}
// Draw bitmap on the screen
display.drawBitmap(0, 0, epd_bitmap_allArray[currentImageIndex], 128, 64, 1);
display.display();
delay(2000);
display.clearDisplay();
}
int getRandomInRange(int max) {
return random(1, max);
}