/*
* OLED Animation Example with hackster.io logo
* https://www.hackster.io/usini/pixel-art-on-oled-display-7f8697
* U8g2lib.h from https://github.com/olikraus/U8g2_Arduino/blob/master/src/U8g2lib.h
*/
#include <Wire.h> //I2C
#include <U8g2lib.h>
#include <AsyncDelay.h>
#include "logo.h"
AsyncDelay tick;
// U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
// I2C SSD1306 128x64 from U8g2 Library
U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
const int FPS = 1000 / 30; //30FPS
bool animation_direction = false;
int animation_state = 0;
void setup() {
u8g2.begin();
tick.start(FPS, AsyncDelay::MILLIS);
}
void loop() {
if (tick.isExpired()) {
drawAnimation();
if (animation_direction) {
animation_state--;
} else {
animation_state++;
}
if (animation_state == 5) {
animation_direction = true;
}
if (animation_state == 0) {
animation_direction = false;
}
tick.repeat();
}
}
void drawAnimation() {
u8g2.firstPage();
do {
switch (animation_state) {
case 0:
u8g2.drawXBMP(0, 0, logo_width, logo_height, logo_1);
break;
case 1:
u8g2.drawXBMP(0, 0, logo_width, logo_height, logo_2);
break;
case 2:
u8g2.drawXBMP(0, 0, logo_width, logo_height, logo_3);
break;
case 3:
u8g2.drawXBMP(0, 0, logo_width, logo_height, logo_4);
break;
case 4:
u8g2.drawXBMP(0, 0, logo_width, logo_height, logo_5);
break;
case 5:
u8g2.drawXBMP(0, 0, logo_width, logo_height, logo_6);
break;
}
} while ( u8g2.nextPage() );
}