//画一个V
//调用u8glib库
#include "U8g2lib.h"

//创建一个对象
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);



// void U8GLIB::drawLine(u8g_uint_t x1, u8g_uint_t y1, u8g_uint_t x2, u8g_uint_t y2)
//参数为: (x1:线段起始点横坐标 y1:线段起始点纵坐标 x2:线段结束点横坐标 y2:线段结束点纵坐标)
// 画线函数
void draw() {
  // 左边
  u8g2.drawLine(7, 10, 40, 55);
  u8g2.drawLine(8, 10, 41, 55);
  u8g2.drawLine(9, 10, 42, 55);
  u8g2.drawLine(37, 10, 10, 55);
  u8g2.drawLine(38, 10, 11, 55);
  u8g2.drawLine(39, 10, 12, 55);

  // 右边
  u8g2.drawLine(77, 10, 110, 55);
  u8g2.drawLine(78, 10, 111, 55);
  u8g2.drawLine(79, 10, 112, 55);
  u8g2.drawLine(107, 10, 80, 55);
  u8g2.drawLine(108, 10, 81, 55);
  u8g2.drawLine(109, 10, 82, 55);
}



// void U8GLIB::drawTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
//参数为:(x0:一个角的横坐标 y0:一个角的纵坐标 x1:另一个角的横坐标 y1:另一个角的纵坐标 x2:最后一个角的横坐标 y2:最后一个角的纵坐标)
//画三角形
void angle() {
  u8g2.drawTriangle(64, 12, 44, 52, 84, 52);
}


// void U8GLIB::drawFrame(u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h)
//参数是:(x:矩形左上角横坐标 y:矩形左上角纵坐标 w:矩形的宽 h:矩形的高)(高和宽的单位都是像素)
//空心矩阵
void Rectangle() {
  u8g2.drawFrame(44, 12, 40, 40);
}


// void U8GLIB::drawRFrame(u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, u8g_uint_t r)
//参数是: (x:圆角矩形左上角横坐标 y:圆角矩形左上角纵坐标 w:圆角矩形宽度 h:圆角矩形高度 r:圆角弧度的半径)
//圆角空心矩形
// 注意:最好要满足两个公式,使用时最好加上if来判断是否符合要求 w > = 2 * x * ( r + 1 ) h > = 2 * x * ( r + 1 ),不然会出现编译不了
void R_Rcetangle(){
  u8g2.drawRFrame(44,12,40,20,10);
}


// void U8GLIB::drawCircle(u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t opt = U8G_DRAW_ALL)
//参数是:(x0:圆心的横坐标 y0:圆心的纵坐标 rad:圆的半径 opt:见下表)
// U8G_DRAW_UPPER_RIGHT        上部右侧 1/4 圆弧
// U8G_DRAW_UPPER_LEFT         上部左侧 1/4 圆弧
// U8G_DRAW_LOWER_LEFT         下部左侧 1/4 圆弧
// U8G_DRAW_LOWER_RIGHT        下部右侧 1/4 圆弧
// U8G_DRAW_ALL                整圆(默认)
//空心圆
void circle(){
   uint8_t opt;
  u8g2.drawCircle(64,32,30);
}
//实心圆
//参数一样,函数名不一样
void D_circle(){
  u8g2.drawDisc(64,32,15);
}


// void drawEllipse(u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rx, u8g_uint_t ry, uint8_t opt)
//参数是:(x0:椭圆圆心的横坐标 y0:椭圆圆心的纵坐标 rx:水平方向半径 ry:垂直方向半径 rad:圆的半径 opt:见下表)
// U8G_DRAW_UPPER_RIGHT        上部右侧 1/4 椭圆弧
// U8G_DRAW_UPPER_LEFT         上部左侧 1/4 椭圆弧
// U8G_DRAW_LOWER_LEFT         下部左侧 1/4 椭圆弧
// U8G_DRAW_LOWER_RIGHT        下部右侧 1/4 椭圆弧
// U8G_DRAW_ALL                整圆(默认)

//空心椭圆
void ellipse(){
u8g2.drawEllipse(64,32,20,10);
}

// 实心椭圆
void F_ellipse(){
u8g2.drawFilledEllipse(64,32,20,10);
}

/*************************************************************************************************************************/
void setup() {

  u8g2.begin();
}

void loop() {
  // put your main code here, to run repeatedly:
  u8g2.firstPage();

  //画线操作要有do while循环或者sendBuffer,都要清除缓存,不然会叠在一起
  //do while操作
  do {
    draw();
    delay(3000);

  } while (u8g2.nextPage());
  u8g2.clearBuffer();
  do {
    angle();
    R_Rcetangle();
    delay(3000);
  } while (u8g2.nextPage());
u8g2.clearBuffer();
  do {
    Rectangle();
    circle();
    D_circle();
    delay(3000);
  } while (u8g2.nextPage());
u8g2.clearBuffer();
  do {
    ellipse();
    delay(3000);
  } while (u8g2.nextPage());
u8g2.clearBuffer();
  do {
   F_ellipse();
    delay(3000);
  } while (u8g2.nextPage());



//sendBuffer操作
//  u8g2.clearBuffer();
// draw();
//  u8g2.sendBuffer();
// delay(3000);
// u8g2.clearBuffer();


//  u8g2.clearBuffer();
// angle();
// u8g2.sendBuffer();
// delay(3000);

}