// simple turbo boost gauge for Arduino, 128x64 OLED display and a potentiometer
//
// based on the "u8glib_progress_bar" project by urish - https://wokwi.com/arduino/projects/300867986768527882
//
// created by upir
// full-length youtube tutorial: https://youtu.be/JXmw1xOlBdk
// links for tools used for this project:
// WOWKI emulator: https://wokwi.com/
// Start project from urish: https://wokwi.com/arduino/projects/300867986768527882
// Photopea (online graphics editor): https://www.photopea.com/
// Gamer font: https://www.dafont.com/gamer-2.font?text=-1+2+3+4+5+6+7+8+TURBO+turbo+boost
// Image2CPP tool: https://javl.github.io/image2cpp/
// Pressure sensor with Arduino: https://www.youtube.com/watch?v=MRNc7XUHBks
#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0 | U8G_I2C_OPT_NO_ACK | U8G_I2C_OPT_FAST); // Fast I2C / TWI
// U8GLIB_SSD1306_128X64 u8g(13, 11, 8, 9, 10); // SPI connection
// for SPI connection, use this wiring:
// GND > GND
// VCC > 5V
// SCL > 13
// SDA > 11
// RES > 10
// DC > 9
// CS > 8
// 'bg_top', 128x25px
// top part of the background, including the meter background, tickmarks and numbers
const unsigned char epd_bitmap_bg_top [] PROGMEM = {
0xf8, 0x00, 0x00, 0x01, 0xf0, 0x00, 0x00, 0x0e, 0x7c, 0x00, 0x00, 0x1c, 0xf8, 0x00, 0x00, 0x00,
0xd8, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x06, 0x6c, 0x00, 0x00, 0x0c, 0xc0, 0x00, 0x00, 0x00,
0xd8, 0x00, 0x00, 0x01, 0xf0, 0x00, 0x00, 0x06, 0x6c, 0x00, 0x00, 0x0c, 0xf8, 0x00, 0x00, 0x00,
0xd8, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x06, 0x6c, 0x00, 0x00, 0x0c, 0x18, 0x00, 0x00, 0x00,
0xd8, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x06, 0x6c, 0x00, 0x00, 0x0c, 0x18, 0x00, 0x00, 0x00,
0xf8, 0x00, 0x00, 0x01, 0xf0, 0x00, 0x00, 0x0f, 0x7c, 0x00, 0x00, 0x1e, 0xf8, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x20, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02,
0x20, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02,
0x20, 0x00, 0x40, 0x00, 0x40, 0x00, 0x80, 0x00, 0x80, 0x01, 0x00, 0x01, 0x00, 0x02, 0x00, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x55, 0x55, 0x55, 0x55,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0xaa, 0xa9,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x55, 0x55, 0x55, 0x55,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0xaa, 0xa9,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x55, 0x55, 0x55, 0x55,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0xaa, 0xa9,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x55, 0x55, 0x55, 0x55,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0xaa, 0xa9,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x55, 0x55, 0x55, 0x55,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0xaa, 0xa9,
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe
};
int progress = 0; // progress of the gauge
void setup() {
//u8g.setFont(u8g_font_tpssb); // no need to set the font, as we are not drawing any strings
u8g.setColorIndex(1); // set the color to white
pinMode(A0, INPUT); // set the pinmode for A0 to input to read the potentiometer value
}
void loop() {
u8g.firstPage();
do {
u8g.setColorIndex(1); // white color
u8g.drawBitmapP( 0, 0, 128/8, 25, epd_bitmap_bg_top); // top part of bg
//u8g.setColorIndex(0); // black color
//u8g.drawBox(1, 12, 126, 12); // rectangle covering the fullscreen background
u8g.setColorIndex(1); // white color
u8g.drawBox(2, 13, map(progress, 0, 1023, 0, 124), 10); // actual gauge fill, remapped from 0-1023 to 0-124 (maximum rectangle size)
} while ( u8g.nextPage() );
progress = analogRead(A0); // read the potentiometer value, 0-1023 for 0-5V
// if (progress < 100) { // automatically increase the progress value (not driven by potentiometer)
// progress++;
// } else {
// progress = 0;
// }
}