本帖最后由 iggy 于 2020-3-5 16:38 编辑
我想用按键实现按下后OLED唤醒,延时后自动休眠,但上传后屏幕周期闪烁,请问如何修改?
#include <U8g2lib.h>
#include <NTPClient.h>
#include <WiFi.h> // for WiFi shield
#include <WiFiUdp.h>
const char *ssid = "SSID";
const char *password = "PASSWORD";
const int EN = 25;
int buttonState = 0;
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0,/*CS*/U8X8_PIN_NONE);
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", 8*3600, 10*60*1000);
void setup()
{
pinMode(EN,INPUT);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print (".");
}
timeClient.begin();
Serial.begin(115200);
u8g2.begin();
u8g2.setContrast(1);
u8g2.setDrawColor(1);
u8g2.setFontPosTop();
u8g2.setFontDirection(0);
}
void loop()
{
timeClient.update();
Serial.println(timeClient.getFormattedTime());
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_logisoso28_tn);
u8g2.setCursor(0,22);
u8g2.println(timeClient.getFormattedTime());
u8g2.sendBuffer();
delay(1000);
buttonState = digitalRead(EN);
if (buttonState == HIGH)
{
u8g2.setPowerSave(0);
delay(5000);
}
else
{
u8g2.setPowerSave(1);
}
}
|