// 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
int frame = 0;      // frame for the inner part of the icon

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(1);                                      // white color      
      u8g.drawBox(2, 21, 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
  frame = frame+1;            // increase the frame for the inner part of the icon
  if (frame > 2) {frame = 0;} // there are total of 3 frames for the animation

  // if (progress < 100) {    // automatically increase the progress value (not driven by potentiometer)
  //   progress++;
  // } else {
  //   progress = 0;
  // }


}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
ssd1306:DATA
ssd1306:CLK
ssd1306:DC
ssd1306:RST
ssd1306:CS
ssd1306:3V3
ssd1306:VIN
ssd1306:GND
pot1:GND
pot1:SIG
pot1:VCC