#include <Arduino.h>
#include <WiFi.h>
#include <WiFiMulti.h>
#include <ESPping.h>
#include <SevenSeg-74HC595.h>
#define USE_SERIAL Serial
// Pin connected to DS of 74HC595 AKA DIO
const uint8_t dio {4}; // // Board pin # of ESP32 WROOM-32 uPesy dev Board
// Pin connected to ST_CP of 74HC595 AKA RCLK
const uint8_t rclk {2}; // Board pin # of ESP32 WROOM-32 uPesy dev Board
// Pin connected to SH_CP of 74HC595 AKA SCLK
const uint8_t sclk {0}; // Board pin # of ESP32 WROOM-32 uPesy dev Board
SevenSeg74HC595 myLedDisp(sclk, rclk, dio, true, 4);
WiFiMulti wifiMulti;
#define LED_RED_PIN 25
#define LED_GREEN_PIN 26
void setup() {
USE_SERIAL.begin(115200);
USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();
pinMode(LED_RED_PIN, OUTPUT);
pinMode(LED_GREEN_PIN, OUTPUT);
myLedDisp.begin();
handle_no_internet();
for (uint8_t t = 2; t > 0; t--) {
//USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
USE_SERIAL.flush();
delay(1000);
}
wifiMulti.addAP("SSID", "PASS"); //根据wifi修改
}
void loop() {
// wait for WiFi connection
if ((wifiMulti.run() == WL_CONNECTED)) {
const char* test_server = "api4.mimikko.cn";
const char* internet_check_server = "www.baidu.com";
if (Ping.ping(test_server,1) > 0) {
handle_server_OK(Ping.averageTime());
} else {
if (Ping.ping(internet_check_server,1) > 0) {
handle_server_dead();
}
else{
handle_no_internet();
}
}
}
else{
handle_no_internet();
}
delay(5000);
}
void handle_no_internet(){
//USE_SERIAL.println("no internet");
myLedDisp.print/**/("----");
myLedDisp.noBlink();
digitalWrite(LED_RED_PIN,LOW);
digitalWrite(LED_GREEN_PIN,LOW);
}
void handle_server_OK(float ping_time){
//USE_SERIAL.println("server OK");
if(ping_time<100.0){
myLedDisp.print/**/(ping_time, 2, true);
}
else if(ping_time<1000.0){
myLedDisp.print/**/(ping_time, 1, true);
}
else{
myLedDisp.print/**/(ping_time, 0, true);
}
myLedDisp.noBlink();
digitalWrite(LED_RED_PIN,HIGH);
digitalWrite(LED_GREEN_PIN,LOW);
}
void handle_server_dead(){
//USE_SERIAL.println("server dead");
myLedDisp.print/**/("Err");
myLedDisp.blink(500);
digitalWrite(LED_RED_PIN,LOW);
digitalWrite(LED_GREEN_PIN,HIGH);
}
这里有问题,一些代码是发不出的,好像遇到“print (” (把里面空格去掉)就会提示没有权限的错误,所以我只能写成print/**/(
了