Skip to content

Commit

Permalink
增加GPIO0刷新全屏功能
Browse files Browse the repository at this point in the history
  • Loading branch information
88431844 committed Mar 15, 2021
1 parent 3e3137c commit 730d23e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
3 changes: 3 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ lib_deps =
tzapu/WiFiManager@^0.16.0
olikraus/U8g2@^2.28.8
jchristensen/Timezone@^1.2.4
lennarthennigs/Button2@^1.6.0
upload_speed = 115200
monitor_speed = 115200
38 changes: 36 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "DEV_Config.h"
#include "EPD.h"
#include <stdlib.h>
#include <Button2.h>

// !!!!!!!!!!! /Arduino/libraries/U8g2/src/clib/u8g2.h 去掉 #define U8G2_16BIT 注释,让2.9寸墨水屏显示区域变大成整屏
U8G2_IL3820_V2_296X128_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/14, /* data=*/13, /* cs=*/15, /* dc=*/4, /* reset=*/2); // ePaper Display, lesser flickering and faster speed, enable 16 bit mode for this display!
Expand All @@ -29,6 +30,9 @@ ESP8266WebServer esp8266_server(80);

String todo = " 生命不息 折腾不止";

#define BUTTON_PIN 0
Button2 button = Button2(BUTTON_PIN);

//函数声明
void handleCLEAR();
void clearDis();
Expand All @@ -41,6 +45,7 @@ void configModeCallback(WiFiManager *myWiFiManager);
void updateDisplay(String todo);
String changeWeek(int weekSum);
String getParam(String name);
void handler(Button2 &btn);

void setup()
{
Expand Down Expand Up @@ -71,11 +76,16 @@ void setup()

webInit();
myMDNSinit();

button.setClickHandler(handler);
button.setLongClickHandler(handler);
button.setDoubleClickHandler(handler);
button.setTripleClickHandler(handler);
}

void loop()
{

button.loop();
MDNS.update();
esp8266_server.handleClient(); // 处理http服务器访问

Expand All @@ -89,7 +99,6 @@ void loop()
updateDisplay(todo);
}
}
delay(500);
}

void configModeCallback(WiFiManager *myWiFiManager)
Expand Down Expand Up @@ -316,6 +325,8 @@ void clearDis()

u8g2.begin();
u8g2.enableUTF8Print();


}
void myMDNSinit()
{
Expand All @@ -336,3 +347,26 @@ void myMDNSinit()
// Add service to MDNS-SD
MDNS.addService("http", "tcp", 80);
}
void handler(Button2 &btn)
{
switch (btn.getClickType())
{
case SINGLE_CLICK:
Serial.print("single ");
clearDis();
break;
case DOUBLE_CLICK:
Serial.print("double ");
break;
case TRIPLE_CLICK:
Serial.print("triple ");
break;
case LONG_CLICK:
Serial.print("long");
break;
}
Serial.print("click");
Serial.print(" (");
Serial.print(btn.getNumberOfClicks());
Serial.println(")");
}

0 comments on commit 730d23e

Please sign in to comment.