#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
// R0 no rotation , R1 90, R2 180, R3 270 , R4 MIRROR, MIRROR_VERTICAL
// https://github.com/olikraus/u8g2/wiki/u8g2reference

const byte screen_width = 127;
const byte col1x = 3;
const byte col2x = 25;
const byte row1  = 11;
const byte bar_row1  = 3; //폰트와 바의 시작점이 다름
const byte row_space  = 11;
const byte max_bar_length = 80;
const byte max_bar_height = 8;


void setup(void) {
  Serial.begin(9600);
  u8g2.begin(); // 메뉴키 6개 감지도 가능하다

  randomSeed(analogRead(0));
}

void loop(){
    
    Disp();
    delay(200);
}


void Disp() {
  // u8g2.clearBuffer();					// clear the internal memory
  // u8g2.setFont(u8g2_font_ncenB08_tr);	// choose a suitable font
  // u8g2.drawStr(0,10,"Hello World!");	// write something to the internal memory
  // delay(1000);  
  
   

  u8g2.firstPage();
  do {
    /*
    fonts
    u8g2.setFont(u8g_font_profont11r); // height 11
    u8g2.setFont(u8g2_font_ncenB14_tr);  // 2x 폰트
    u8g.setFont(u8g_font_profont29r);    // height 29


    //버튼형태로 그리기
    u8g2.setFont(u8g2_font_ncenB08_tr);
    u8g2.drawButtonUTF8(0, 15,U8G2_BTN_BW1 | U8G2_BTN_INV, 30, 1, 1, "A0");  // U8G2_BTN_INV, 깜빡임효과
    */


       
    // 큰 반원 왼쪽/오른쪽
    // u8g2.drawCircle(px1, py1, arrow_length+15, U8G2_DRAW_UPPER_RIGHT);
    // u8g2.drawCircle(px1, py1, arrow_length+15, U8G2_DRAW_UPPER_LEFT);
    
    
    // fixed layout
    u8g2.setFont(u8g_font_profont11r); 
    u8g2.drawStr(col1x, row1,    "CPU");
    u8g2.drawStr(col1x, row1+row_space, "MEM");
    u8g2.drawStr(col1x, row1+(row_space*2), "HDD");
    u8g2.drawFrame(col2x,bar_row1, max_bar_length, max_bar_height);
    u8g2.drawFrame(col2x,bar_row1+row_space, max_bar_length, max_bar_height);
    u8g2.drawFrame(col2x,bar_row1+(row_space*2), max_bar_length, max_bar_height);

    u8g2.drawBox(col2x,bar_row1, max_bar_length-50, max_bar_height);
    u8g2.drawBox(col2x,bar_row1+row_space, max_bar_length-20, max_bar_height);
    u8g2.drawBox(col2x,bar_row1+(row_space*2), max_bar_length-30, max_bar_height);
    //u8g2.drawLine(px1, py1, px2, py2);  
    

    u8g2.setCursor(85,45);
    

 
  } while ( u8g2.nextPage() );
}