// C++ code
#include <WiFi.h>
#include <Adafruit_NeoPixel.h>
#include <driver/adc.h>
#include "text.h"
#define NTP_SERVER1 "ntp.aliyun.com"
#define NTP_SERVER2 "ntp.tencent.com"
#define NTP_SERVER3 "ntp.sjtu.edu.cn"
#define UTC_OFFSET 8 * 3600
#define UTC_OFFSET_DST 0
#define LED_PIN 21
#define LED_COUNT 224
int potPin = 2;
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
uint32_t color = strip.Color(0, 0, 255);
bool showDot = true;
int brightness = 255;
float potValue = 0;
void setup() {
Serial.begin(115200);
pinMode(potPin, INPUT);
strip.begin();
strip.setBrightness(brightness);
displayText(set_wifi);
WiFi.begin("Wokwi-GUEST", "", 6);
// WiFi.begin("HUAWEI-YYLX", "maisidi123456", 6);
while (WiFi.status() != WL_CONNECTED) {
displayText(connect);
delay(500);
Serial.print("WiFi status:");
Serial.println(WiFi.status());
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("online");
displayText(online);
delay(1000);
Serial.println("get time");
// // LCD.println("Updating time...");
configTime(UTC_OFFSET, UTC_OFFSET_DST, NTP_SERVER1, NTP_SERVER2, NTP_SERVER3);
delay(2000);
}
void loop() {
delay(500);
showTime();
potValue = digitalRead(potPin);
Serial.println(potValue);
}
void showTime() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
displayText(connect_err);
Serial.println("Connection Err");
return;
}
strip.clear();
int hour1 = timeinfo.tm_hour / 10; // 小时十位数字
int hour2 = timeinfo.tm_hour % 10; // 小时个位数字
int minute1 = timeinfo.tm_min / 10; // 分钟十位数字
int minute2 = timeinfo.tm_min % 10; // 分钟个位数字
// 显示小时十位数字
displayNum(0, digit[hour1]);
// 显示小时个位数字
displayNum(6, digit[hour2]);
// 显示分钟十位数字
displayNum(15, digit[minute1]);
// 显示分钟个位数字
displayNum(21, digit[minute2]);
// 显示冒号
displayDot(showDot ? dot_show : dot_hide);
// 显示星期
displayNum(27, weeks[timeinfo.tm_wday]);
strip.show();
Serial.print(timeinfo.tm_hour);
Serial.print(":");
Serial.print(timeinfo.tm_min);
Serial.print(":");
Serial.print(timeinfo.tm_sec);
Serial.print(" ");
Serial.println(timeinfo.tm_wday);
}
void displayNum(int startAt, int data[7][5]) {
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 5; j++) {
if (data[i][j] == 1) {
int index = 7 * (startAt + j) + i;
strip.setPixelColor(index, color);
}
}
}
}
void displayDot(int data[7][2]) {
showDot = !showDot;
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 2; j++) {
if (data[i][j] == 1) {
int index = 7 * (j + 12) + i;
strip.setPixelColor(index, color);
}
}
}
}
void displayText(int data[7][32]) {
strip.clear();
for (int row = 0; row < 7; row++) {
for (int col = 0; col < 32; col++) {
int index = 7 * col + row;
if (data[row][col] == 1) {
strip.setPixelColor(index, color);
}
}
}
strip.show();
}