This looked like fun. So I tried it for myself. However I simplified it somewhat by putting the tables in a separate tab:
horses.cpp:
#include <Arduino.h>
static const unsigned char PROGMEM horse00[] = {
...
};
const uint8_t *horses[] = { //global array of pointers to the private data
horse00, horse01, horse02, horse03, horse04, horse05, horse06, horse07,
horse08, horse09, horse10, horse11, horse12, horse13, horse14
};
OLED_Horse.ino:
/*
* Image of Horse Gallping originally photograph by Eadweard Muybridge. For more information
* about Eadweard Muybridge go to: https://en.wikipedia.org/wiki/Eadweard_Muybridge
* Image: http://animationresources.org/wp-content/uploads/2015/05/Muybridge_race_horse_gallop.jpg
* Software to convert images to 128x64 at: http://www.ablab.in/image2glcd-software/
*
* Minimal sketch to run animation with 128x64 I2C SSD1306. Written by Greg Stievenart with no
* claim to or any information provided in this code.
*/
#include <Wire.h> // requried to run I2C SSD106
#include <SPI.h> // requried to run I2C SSD106
#include <Adafruit_GFX.h> // https://github.com/adafruit/Adafruit-GFX-Library
#include <Adafruit_SSD1306.h> // https://github.com/adafruit/Adafruit_SSD1306
#define OLED_CLK 13
#define OLED_MOSI 11
#define OLED_RESET 8
#define OLED_DC 9
#define OLED_CS 10
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS); // I use SPI
//Adafruit_SSD1306 display(OLED_RESET); // reset required for SSD1306
extern const uint8_t *horses[]; // private tables and public pointer array in separate file
int framecount = 0;
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // required to run SSD1306
display.clearDisplay();
}
void loop()
{
display.fillRect(0, 0, 128, 64, WHITE);
if (++framecount > 14) framecount = 0;
display.drawBitmap(0, 0, horses[framecount], 128, 64, BLACK);
display.display();
}
Then I wondered what it would look like on a TFT. This just required a helper function to draw a Mono image:
TFT_horse.ino
/*
* Image of Horse Gallping originally photograph by Eadweard Muybridge. For more information
* about Eadweard Muybridge go to: https://en.wikipedia.org/wiki/Eadweard_Muybridge
* Image: http://animationresources.org/wp-content/uploads/2015/05/Muybridge_race_horse_gallop.jpg
* Software to convert images to 128x64 at: http://www.ablab.in/image2glcd-software/
*
* Minimal sketch to run animation with 128x64 I2C SSD1306. Written by Greg Stievenart with no
* claim to or any information provided in this code.
*/
#include <Adafruit_GFX.h> // https://github.com/adafruit/Adafruit-GFX-Library
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
extern const uint8_t *horses[];
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
int framecount = 0;
void draw_mono(int x, int y, const uint8_t *buf, int w, int h, uint16_t fg, uint16_t bg)
{
uint8_t row, col, c, first = 1, idx, mask;
uint8_t *temp = (uint8_t*)buf;
uint16_t color;
tft.setAddrWindow(x, y, x + w - 1, y + h - 1); //we draw left-right, then down
for (row = 0; row < h; row++) {
mask = 0;
for (col = 0; col < w; col++) {
// if (mask == 0) mask = 0x80, c = pgm_read_byte((uint8_t*)buf + col/8 + (row * (w/8)));
if (mask == 0) mask = 0x80, c = pgm_read_byte(temp++);
color = (c & mask) ? fg : bg;
tft.pushColors(&color, 1, first);
first = 0;
mask >>= 1;
}
}
}
void setup(void)
{
uint16_t ID = tft.readID();
if (ID == 0xD3D3) ID = 0x9481; // write-only shield
tft.begin(ID);
tft.fillScreen(BLUE);
}
void loop()
{
if (++framecount > 14) framecount = 0;
draw_mono(0, 0, horses[framecount], 128, 64, BLACK, CYAN);
}
If your TFT library has a Mono Bitmap method, you don't even need a helper function.
Both the OLED and the TFT animate at about the same speed on a Uno.
I have not altered stievenart's image data. The Monochrome image might look better with "less" contrast.
David.