// simple project using Arduino UNO and 128x64 SSD1306 IIC OLED Display to display animated icon from www.icons8.com
// created by upir, 2023
// youtube channel: https://www.youtube.com/upir_upir
// YOUTUBE VIDEO: https://youtu.be/o3PhC_VJdXo
// Links from the video:
// WOKWI animator: https://animator.wokwi.com/
// Animated icons: https://icons8.com/icons/set/popular--animated
// Infinity icon: https://icons8.com/icons/set/infinity--animated
// 128x64 SSD1306 OLED Display 1.54": https://s.click.aliexpress.com/e/_DCYdWXb
// 128x64 SSD1306 OLED Display 0.96": https://s.click.aliexpress.com/e/_DCKdvnh
// 128x64 SSD1306 OLED Display 2.42": https://s.click.aliexpress.com/e/_DFdMoTh
// Arduino UNO: https://s.click.aliexpress.com/e/_AXDw1h
// Arduino breadboard prototyping shield: https://s.click.aliexpress.com/e/_ApbCwx
// Image2cpp (convert image to c-style array): https://javl.github.io/image2cpp/
// Photopea (online graphics editor like Photoshop): https://www.photopea.com/
// Piskel Application (online animation editor): https://www.piskelapp.com/p/create/sprite
// Related videos with Arduino UNO and 128x64 OLED screen:
// Arduino OLED menu: https://youtu.be/HVHVkKt-ldc
// U8g vs U8g2: https://youtu.be/K5e0lFRvZ2E
// Arduino Parking Sensor - https://youtu.be/sEWw087KOj0
// Turbo pressure gauge with Arduino and OLED display - https://youtu.be/JXmw1xOlBdk
// Arduino Car Cluster with OLED Display - https://youtu.be/El5SJelwV_0
// Knob over OLED Display - https://youtu.be/SmbcNx7tbX8
// Arduino + OLED = 3D ? - https://youtu.be/kBAcaA7NAlA
// Arduino OLED Gauge - https://youtu.be/xI6dXTA02UQ
// Smaller & Faster Arduino - https://youtu.be/4GfPQoIRqW8
// Save Image from OLED Display to PC - https://youtu.be/Ft2pRMVm44E
#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h> // library required for IIC communication
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // initialization for the used OLED display
// 's-l1600', 128x32px
const unsigned char epd_bitmap_s_l1600 [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xfc, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xff, 0x8f, 0xff, 0x07, 0xff, 0x3f, 0xf8, 0x7f, 0xf8, 0xdf, 0xff, 0xff, 0x01, 0xfe, 0x3f, 0x00,
0xfe, 0x8f, 0xff, 0xc3, 0xff, 0xff, 0xf0, 0xff, 0xf0, 0xdf, 0xff, 0xff, 0x07, 0xfe, 0x3f, 0x00,
0xf8, 0x01, 0xfc, 0xe0, 0x0f, 0xfc, 0xc1, 0xff, 0xc1, 0x03, 0x7f, 0xf0, 0x0f, 0xf0, 0x7f, 0x00,
0xf8, 0x01, 0xfc, 0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 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'digit_0', 16x28px
const unsigned char bitmap_digit_0 [] PROGMEM = {
0xf0, 0xff, 0xf8, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfc, 0x3f, 0xfc,
0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc,
0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0xff, 0xff,
0xff, 0xff, 0xff, 0x7f, 0xff, 0x3f, 0xff, 0x1f
};
// 'digit_1', 16x28px
const unsigned char bitmap_digit_1 [] PROGMEM = {
0x80, 0x1f, 0xc0, 0x1f, 0xe0, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f,
0x80, 0x1f, 0x80, 0x1f, 0x80, 0x1f, 0x80, 0x1f, 0x80, 0x1f, 0x80, 0x1f, 0x80, 0x1f, 0x80, 0x1f,
0x80, 0x1f, 0x80, 0x1f, 0x80, 0x1f, 0x80, 0x1f, 0x80, 0x1f, 0x80, 0x1f, 0x80, 0x1f, 0x80, 0x1f,
0x80, 0x1f, 0x80, 0x1f, 0x80, 0x1f, 0x80, 0x1f
};
// 'digit_2', 16x28px
const unsigned char bitmap_digit_2 [] PROGMEM = {
0xf0, 0x7f, 0xf8, 0xff, 0xfc, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfc, 0x3f, 0xfc,
0x3f, 0xfc, 0x00, 0xfc, 0x00, 0xfe, 0x00, 0xff, 0x80, 0x7f, 0xc0, 0x3f, 0xf0, 0x1f, 0xf8, 0x0f,
0xfc, 0x07, 0xfe, 0x03, 0xff, 0x00, 0x7f, 0x00, 0x3f, 0x00, 0x3f, 0x00, 0x3f, 0x00, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
// 'digit_3', 16x28px
const unsigned char bitmap_digit_3 [] PROGMEM = {
0xf0, 0x7f, 0xfc, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xfc, 0x1f, 0xfc,
0x1f, 0xfc, 0x00, 0xfc, 0x00, 0xfc, 0x00, 0x7f, 0x00, 0x3f, 0x00, 0x1f, 0x00, 0xff, 0x00, 0xff,
0x00, 0xff, 0x00, 0xfc, 0x00, 0xfc, 0x1f, 0xfc, 0x1f, 0xfc, 0x1f, 0xfc, 0x3f, 0xfc, 0xff, 0xff,
0xff, 0xff, 0xff, 0x7f, 0xff, 0x3f, 0xff, 0x1f
};
// 'digit_4', 16x28px
const unsigned char bitmap_digit_4 [] PROGMEM = {
0x00, 0x0e, 0x00, 0x1e, 0x00, 0x3f, 0x00, 0x7f, 0x80, 0xff, 0xc0, 0xff, 0xc0, 0xff, 0xe0, 0xff,
0xe0, 0xff, 0xf0, 0xff, 0xf0, 0xfd, 0xf8, 0xfd, 0xf8, 0xfc, 0xfc, 0xfc, 0x7c, 0xfc, 0x7e, 0xfc,
0x3e, 0xfc, 0x3f, 0xfc, 0xff, 0xff, 0xfe, 0xff, 0xfc, 0xff, 0xfc, 0xff, 0xf8, 0xff, 0x00, 0xfc,
0x00, 0xfc, 0x00, 0xfc, 0x00, 0xfc, 0x00, 0xfc
};
// 'digit_5', 16x28px
const unsigned char bitmap_digit_5 [] PROGMEM = {
0xfe, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x3f, 0x00, 0x3f, 0x00,
0x3f, 0x00, 0x3f, 0x00, 0x7f, 0x00, 0xff, 0x0f, 0xff, 0x1f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0xff,
0x00, 0xfc, 0x00, 0xfc, 0x00, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfe, 0xff, 0xff,
0xff, 0xff, 0xfe, 0xff, 0xfc, 0xff, 0xf8, 0xff
};
// 'digit_6', 16x28px
const unsigned char bitmap_digit_6 [] PROGMEM = {
0xf0, 0x7f, 0xf8, 0xff, 0xfc, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfc, 0x3f, 0xfc,
0x3f, 0xfc, 0x3f, 0x00, 0x3f, 0x00, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfe, 0xff, 0xff,
0xff, 0x7f, 0xff, 0x3f, 0xff, 0x1f, 0xff, 0x0f
};
// 'digit_7', 16x28px
const unsigned char bitmap_digit_7 [] PROGMEM = {
0xff, 0x0f, 0xff, 0x1f, 0xff, 0x3f, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x7c, 0x1f, 0x7e,
0x1f, 0x7e, 0x00, 0x3f, 0x00, 0x3f, 0x00, 0x3f, 0x80, 0x1f, 0x80, 0x1f, 0x80, 0x1f, 0xc0, 0x0f,
0xc0, 0x0f, 0xe0, 0x0f, 0xe0, 0x07, 0xe0, 0x07, 0xf0, 0x03, 0xf0, 0x03, 0xf0, 0x03, 0xf8, 0x01,
0xf8, 0x01, 0xfc, 0x01, 0xfc, 0x00, 0xfc, 0x00
};
// 'digit_8', 16x28px
const unsigned char bitmap_digit_8 [] PROGMEM = {
0xf0, 0x7f, 0xf8, 0x7f, 0xfc, 0x7f, 0xfe, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x3f, 0x7c, 0x3f, 0x7c,
0x3f, 0x7c, 0x3f, 0x7c, 0x3f, 0x7c, 0x3f, 0x7c, 0xff, 0x3f, 0xff, 0x1f, 0xf8, 0xff, 0xfe, 0xff,
0xff, 0xff, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0xff, 0xff,
0xff, 0xff, 0xff, 0x7f, 0xff, 0x3f, 0xff, 0x1f
};
// 'digit_9', 16x28px
const unsigned char bitmap_digit_9 [] PROGMEM = {
0xe0, 0xff, 0xf8, 0xff, 0xfc, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfc, 0x3f, 0xfc,
0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0x00, 0xfc, 0x00, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0xff, 0xff,
0xff, 0xff, 0xff, 0x7f, 0xff, 0x3f, 0xff, 0x1f
};
// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 800)
const int bitmap_allArray_LEN = 10;
const unsigned char* bitmap_allArray[10] = {
bitmap_digit_0,
bitmap_digit_1,
bitmap_digit_2,
bitmap_digit_3,
bitmap_digit_4,
bitmap_digit_5,
bitmap_digit_6,
bitmap_digit_7,
bitmap_digit_8,
bitmap_digit_9
};
void hondaLogo(int timeSleep){
u8g2.clearBuffer(); // clear the internal memory
u8g2.drawXBMP(0, 0, 128, 32, epd_bitmap_s_l1600); // draw frame of the animation
u8g2.sendBuffer(); // transfer internal memory to the display
delay(timeSleep * 1000);
}
void clear(){
u8g2.clear();
}
void clock(int num){
int offset = 16;
int space = 16;
int padding = 3;
int minuti_unit_x = 112 - padding - offset;
int minuti_dec_x = minuti_unit_x - space - padding;
int point_x = minuti_dec_x - space/2 - 2;
int ore_unit_x = minuti_dec_x - 32 - padding;
int ore_dec_x = ore_unit_x - space - padding;
int hours = num / 3600; // Calcola le ore
int remainingSeconds = num % 3600;
int minutes = remainingSeconds / 60; // Calcola i minuti
u8g2.drawXBMP(minuti_unit_x, 2, 16, 28, bitmap_allArray[minutes % 10]);
u8g2.drawXBMP(minuti_dec_x, 2, 16, 28, bitmap_allArray[minutes / 10]);
u8g2.drawCircle(point_x, 8, 2, U8G2_DRAW_ALL);
u8g2.drawCircle(point_x, 16, 2, U8G2_DRAW_ALL);
u8g2.drawXBMP(ore_unit_x, 2, 16, 28, bitmap_allArray[hours % 10]);
u8g2.drawXBMP(ore_dec_x, 2, 16, 28, bitmap_allArray[hours / 10]);
}
void setup(void) {
u8g2.begin(); // start the u8g2 library
//hondaLogo(5);
}
int count = 0;
bool blink = true;
void loop(void) {
u8g2.firstPage();
do {
clock(count);
count = count +1;
blink = !blink;
//delay(250);
} while ( u8g2.nextPage() );
}