已解决
#include <ESP8266WiFi.h>
const char* ssid = "newifi";
const char* password = "87257258";
#include <Ticker.h>
Ticker ticker;
int count = 0;
void Tickertest()
{
int state = digitalRead(LED_BUILTIN);
digitalWrite(LED_BUILTIN, !state);
++count;
Serial.println(count);
Serial.println(WiFi.localIP());
Serial.println("");
}
void setup() {
WiFi.mode(WIFI_STA);//工作模式
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {//判断是否连上
delay(2000);
Serial.print(".");
}
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
//间隔1秒
ticker.attach(1, Tickertest);
}
void loop() {
} |