#include "U8glib.h"

//screen size is 128x64
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0 | U8G_I2C_OPT_NO_ACK | U8G_I2C_OPT_FAST); // Fast I2C / TWI


int progress = 0; //integer value of the progress
char progress_buffer[20]; //buffer string that we use to display progress as a number
int fps; //fps number to be displayed
char fps_buffer[10];  //the buffer string for the fps that we actually display
unsigned long millis_time;       //time of current frame
unsigned long millis_time_last;  //time of last frame
int xpos=0; //particle x position
int xvel=0; //particle x velocity
int ypos=0; //particle y position
int yvel=0; //particle y velocity
int time_value=0; //time value that increments every loop of the arduino


void setup() {
  //u8g.setFont(u8g_font_tpssb); //you could set the font in the setup code if everything uses the same font
  u8g.setColorIndex(1); //sets everything you draw to be a white pixel as opposed to drawing black pixels
}

void loop() {

  //create a string that says "x% progress" using sprintf()
  sprintf(progress_buffer, "%d%% progress", progress);
  //convert fps integer to a string so it can be displayed
  itoa(fps, fps_buffer, 10);

  //position of a lil waving dot
  //xvel= cos(time_value / 20.0)*5.0; //not gonna use this
  //yvel= cos(time_value / 5.0)*1.5;  //not gonna use this either
  xpos= 64 + cos(time_value/21.0)*64.0;  //particle x position function
  ypos= 58 + sin(time_value / 7.0)*4.0;  //particle y position function
  time_value++;  //increment the time value every arduino loop

//this is the page loop that we use to display and animate each frame (very importatnt)
  u8g.firstPage();
  do {
    u8g.setFont(u8g_font_tpssb);           //set the big font for progress string
    u8g.drawStr(25, 45, progress_buffer);  //draw the progress string
    u8g.drawFrame(0, 10, 128, 20);         //draw the border around the bar
    u8g.drawBox(14, 15, progress, 10);     //draw the progress bar
    u8g.setFont(u8g_font_blipfest_07);     //change to smaller font for fps
    u8g.drawStr(0,5, fps_buffer);          //draw the FPS number
    u8g.drawPixel(xpos, ypos);             //draw the floaty boy
  } while ( u8g.nextPage() );              //ends the page loop

//increment and reset the progress value
  if (progress < 100) {
    progress++;
  } else {
    progress = 0;
  }

// calculate the FPS
  millis_time_last = millis_time;                                  // store last millisecond value
  millis_time = millis();                                          // get millisecond value from the start of the program
  fps = round(1000.0/ (millis_time*1.0-millis_time_last));         // calculate FPS (frames per second) value
}
nano:12
nano:11
nano:10
nano:9
nano:8
nano:7
nano:6
nano:5
nano:4
nano:3
nano:2
nano:GND.2
nano:RESET.2
nano:0
nano:1
nano:13
nano:3.3V
nano:AREF
nano:A0
nano:A1
nano:A2
nano:A3
nano:A4
nano:A5
nano:A6
nano:A7
nano:5V
nano:RESET
nano:GND.1
nano:VIN
nano:12.2
nano:5V.2
nano:13.2
nano:11.2
nano:RESET.3
nano:GND.3
oled1:GND
oled1:VCC
oled1:SCL
oled1:SDA