/*
   程序:  ESP32 OLED 使用 U8G2库
          大家可以尝试一下改写成为FREERTOS
   公众号:孤独的二进制
*/
#include <U8g2lib.h>
#include <Wire.h>
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
int leftpin=12;
int val;
void setup() {

  u8g2.begin();
  pinMode(leftpin, INPUT);
}
byte l=20;
byte ll;
void loop() {
  val=digitalRead(leftpin);


  if(val==0){

ll=ll+10;
//if (ll>60)l=80;
}
  
  u8g2.clearBuffer();					// clear the internal memory 每一秒清屏
  u8g2.setFont(u8g2_font_unifont_t_symbols);	// choose a suitable font
  u8g2.drawRBox(20,35,l,22,7);//the nub 300 out of screen length
  u8g2.drawUTF8(5,30,  "Snowman:");
  u8g2.drawUTF8(35+ll,30,  "☃");//
    
  u8g2.drawStr(2, 65, "0");	// write something to the internal memory

  if(ll>l)
{
 

  for(int i=1;i<5;i++)
  { 
    u8g2.clearBuffer();					// clear the internal memory 每一秒清屏
      u8g2.drawStr(2, 65, "1");	// write something to the internal memory

    u8g2.drawRBox(20,35,l,22,7);//the nub 300 out of screen length
  u8g2.drawUTF8(5,30,  "Snowman:");
  
   u8g2.drawStr(15, 10, "LONELY BINAR Y");	// write something to the internal memory
  
  u8g2.drawUTF8(35+ll,30+i*10,  "☃");//
 u8g2.sendBuffer();	
 }
ll=0;
}


  u8g2.sendBuffer();					// transfer internal memory to the display
  //delay(1000);
  l=l+10;if(l>100)l=20;
}