#include "ESP8266WiFi.h"
#include "BlynkSimpleEsp8266.h"
#include "WidgetRTC.h"
#include "OasisLED.h"
// ===== 連線環境設置 =====
char ssid[] = "yourNetwork"; // your network SSID (name)
char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP)
char auth[] = "........."; // 輸入 BLYNK 的 authkey
volatile byte h,m; //顯示時間用
// ===== 硬體腳位設置 =====
const int dataPin = D3;
const int clkPin = D5;
const int csPin = D6;
// ===== 副函式 Header =====
void WiFiConnect();
void getTime();
void timer_30000(); // 30 sec
// ===== 實體設置 =====
SimpleTimer timer; //中斷定時器
WiFiClient ESPclient;
WidgetRTC rtc;
OasisLED ledDisplay = OasisLED(clkPin, csPin, dataPin);
void setup() {
ESP.wdtDisable();
ESP.wdtEnable(WDTO_8S);
ledDisplay.initialize(); //初使化
ledDisplay.setSpinnerMode(SPIN_NONE);
ledDisplay.setBrightness(0); //設定亮度(0~7) 0最暗
/* 連上 WiFi */
WiFiConnect();
/* Blynk init */
Blynk.config(auth); //輸入Auth,顯示 BLYNK on Arduino 歡迎訊息
Blynk.connect(); // 連線至 BLYNK ,成功後會顯示 Ready
rtc.begin();
while( !(minute()&&second()) ) {Blynk.run();} //等待時間同步
timer_30000(); //LED 更新顯示時間
timer.setInterval(30000L, timer_30000);
}
void loop() {
timer.run();
Blynk.run();
}
/* =====================*/
// ===== timer_30000 ====
/* =====================*/
void timer_30000(){
getTime();
}
/* =====================*/
// ===== timer_30000 ====
/* =====================*/
void getTime(){
ledDisplay.reset();
h = hour();
m = minute();
int real_time = 100*h + m;
ledDisplay.setBrightness(0);
ledDisplay.setValue(real_time);
}
/* =====================*/
// ===== WiFiConnect ====
/* =====================*/
void WiFiConnect(){
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
我將定期推出程式語言的新手教學影片