#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#include <Ticker.h>
int ledOutput = LED_BUILTIN;//板载LED灯
Ticker ticker;//实例化定时器
void setup() {
Serial.begin(9600);//打开串口通讯
pinMode(ledOutput,OUTPUT);//初始化LED状态
ticker.attach(0.1,wifiStatus);//定时执行LED的取反,直到WIFI连接
WiFiManager wifiManager;//实例化自动配网
wifiManager.autoConnect("AP");//启动自动配网
Serial.println("");
Serial.print("ESP8266 Connected to ");
Serial.println(WiFi.SSID());
Serial.print("IP address:\t");
Serial.println(WiFi.localIP());
}
void wifiStatus(){
if (WiFi.status() == WL_CONNECTED){//判断WIFI是否连接
digitalWrite(ledOutput,HIGH);//设置为高。LED灭
ticker.detach();
}
else {
digitalWrite(ledOutput,!digitalRead(ledOutput));//取返led
}
}
void loop() {
// put your main code here, to run repeatedly:
}
利用ticker定时器,每100毫秒检测wifi连接情况,没连接就取反LED提示进行配网,连接成功pin脚为高。关闭led