// simple project using Arduino UNO and 128x64 OLED Display to display analog clock
// note - this project is meant for the 128x128 SH1107 OLED display, but WOKWI currently only supports 128x64 OLED display
// for this reason, the preview here only shows half of the design
// created by upir, 2023
// youtube channel: https://www.youtube.com/upir_upir
// YOUTUBE VIDEO: https://youtu.be/srgsBWHSNSQ
// links from the video:
// 128x128 SH1107 OLED Display: https://s.click.aliexpress.com/e/_DdOCQHj
// 128x64 SSD1306 OLED Display: https://s.click.aliexpress.com/e/_DCKdvnh
// Arduino UNO: https://s.click.aliexpress.com/e/_AXDw1h
// Arduino breadboard prototyping shield: https://s.click.aliexpress.com/e/_ApbCwx
// Photopea (online Photoshop-like tool): https://www.photopea.com/
// u8g2 documentation: https://github.com/olikraus/u8g2/wiki/u8gvsu8g2
// Related videos:
// 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
#include <Arduino.h>
#include <U8g2lib.h> // u8g2 library for drawing on OLED display - needs to be installed in Arduino IDE first
#include <Wire.h> // wire library for IIC communication with the OLED display
#include "Obrazky.h"
#include "fonty.h"
// U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0); // set the OLED display to 128x64px, HW IIC, no rotation, used in WOKWI
U8G2_SH1107_128X128_1_HW_I2C u8g2(U8G2_R0); // final display, 128x128px [page buffer, size = 128 bytes], HW IIC connection
// IIC connection of the OLED display and Arduino UNO
// +5V > +5V
// GND > GND
// SCL (serial clock) > A5 or SCL
// SDA (serial data) > A4 or SDA
const byte interruptPin = 2;
volatile byte stateShot = LOW;
// Bullet indikator
int bullet=16;
int bulletStart=0;
#define SHOT_BUTTON 9
#define RESET_BUTTON 10
unsigned long casomira;
int dobaStisku;
int limitKZ = 1500; // doba drezni RESET_BUTTON pro reset Komory Zasobniku
int limitCZ = 5000; // doba drezni RESET_BUTTON pro reset Celeho Zasobniku
// zasobnik 01
int zasobnikCelkem =120; //pocet kuli v zasobniku
int zasobnikKomora = 40; //pocet kuli v komore zasobniku
int kule = zasobnikCelkem; // celkovy pocet kuli
int kuleKomora = zasobnikKomora; // celkovy pocet kuli v komore zasobniku
int kolikBullet = zasobnikCelkem / bullet; // vypocet kolik kuli prezentule jeden bullet
void setup(void) { // Arduino setup
u8g2.begin(); // begin the u8g2 library
u8g2.setContrast(255); // set display contrast/brightness
//u8g2.setFont(u8g2_font_logisoso28_tf);
u8g2.setColorIndex(1);
pinMode(SHOT_BUTTON, INPUT_PULLUP);
pinMode(RESET_BUTTON, INPUT_PULLUP);
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), shot, CHANGE);
}
void loop(void) { // main Arduino loop
// zjisteni zda doslo ke zmene stavu - void shot
if (stateShot)
{
kule=kule-1;
kuleKomora -=1;
stateShot = LOW;
}
// Reset button - 2s=reset komory - 5s=reset celeho zasobniku
casomira = millis();
while (!digitalRead(RESET_BUTTON))
{
dobaStisku = millis() - casomira;
}
if (dobaStisku >= limitCZ)
{
kule = zasobnikCelkem; // celkovy pocet kuli
kuleKomora = zasobnikKomora; // celkovy pocet kuli v komore zasobniku
dobaStisku = 0;
}
if (dobaStisku >= limitKZ)
{
kuleKomora = zasobnikKomora;
dobaStisku = 0;
}
// vykresleni obrazovky
u8g2.firstPage();
for (int i = 0; i < bullet; i++)
{
u8g2.drawXBMP(bulletStart, 0, 8, 24, epd_bitmap_bulet_8x24);
bulletStart=bulletStart+8;
}
bulletStart=0;
// do {
// vykresleni Bullet indikatoru - CELY ZASOBNIK
// for (int i = 0; i < bullet; i++)
// {
// u8g2.drawXBMP(bulletStart, 0, 8, 24, epd_bitmap_bulet_8x24);
// bulletStart=bulletStart+8;
// }
// bulletStart=0;
// bullet = kule / kolikBullet; //kolik bude bulletu na zaklade poctu kuli
// // vykresleni velkeho cisla - KOMORA ZASOBNIKU
// u8g2.setFont(digi76);
// u8g2.setCursor(21, 105);
// u8g2.print(kuleKomora);
// // vykresleni paticky
// u8g2.setFont(u8g2_font_t0_11_tf);
// u8g2.setCursor(0, 128);
// u8g2.print(zasobnikCelkem);
// u8g2.print("/");
// u8g2.print(zasobnikKomora);
// u8g2.print(" : ");
// u8g2.println(kule);
// u8g2.drawXBMP(128-11-20, 128-8, 16, 8, bitmap_battery[4]); // draw MK logo
// u8g2.drawXBMP(128-11, 128-8, 11, 8, epd_bitmap_MK_LOGO); // draw MK logo
// } while ( u8g2.nextPage() );
}
void shot() {
stateShot = !stateShot; // zmena stavu - pri strelbe
}