#include "U8glib.h"//ssd1306
#include <GyverHTU21D.h>
#include "RTClib.h"
#include <SD.h>
const int chipSelect = 10;
File myFile;
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0 | U8G_I2C_OPT_NO_ACK | U8G_I2C_OPT_FAST); // Fast I2C / TWI
GyverHTU21D htu;
RTC_DS1307 rtc;
int progress = 0;
static const unsigned char PROGMEM Pqe_4[][4]= {{
0X00,0X00,0X00,0X00},{
0x0f,0x0f,0x0f,0x0f},{
0xf0,0xf0,0xf0,0xf0},{
0xff,0xff,0xff,0xff
}};
static const unsigned char PROGMEM logo_bq[][7] = {{//動畫點陣圖
//0
0b01110000,
0b10001000,
0b10011000,
0b10101000,
0b11001000,
0b10001000,
0b01110000},{
//1
0b00100000,
0b01100000,
0b00100000,
0b00100000,
0b00100000,
0b00100000,
0b01110000},{
//2
0b01110000,
0b10001000,
0b00001000,
0b00010000,
0b00100000,
0b01000000,
0b11111000},{
//3
0b01110000,
0b10001000,
0b00001000,
0b00110000,
0b00001000,
0b10001000,
0b01110000},{
//4
0b00010000,
0b10010000,
0b10010000,
0b10010000,
0b11111000,
0b00010000,
0b00010000},{
//5
0b11111000,
0b10000000,
0b11110000,
0b00001000,
0b00001000,
0b10001000,
0b01110000},{
//6
0b00010000,
0b00100000,
0b01000000,
0b11110000,
0b10001000,
0b10001000,
0b01110000},{
//7
0b11111000,
0b00001000,
0b00001000,
0b00010000,
0b00010000,
0b00100000,
0b00100000},{
//8
0b01110000,
0b10001000,
0b10001000,
0b01110000,
0b10001000,
0b10001000,
0b01110000},{
//9
0b01110000,
0b10001000,
0b10001000,
0b01111000,
0b00010000,
0b00100000,
0b01000000},{
//X
0b10001000,
0b10001000,
0b01010000,
0b00100000,
0b01010000,
0b10001000,
0b10001000},{
//%
0b11001000,
0b11001000,
0b00010000,
0b00100000,
0b01000000,
0b10011000,
0b10011000},{
//C
0b10000000,
0b00110000,
0b01001000,
0b10000000,
0b10000000,
0b01001000,
0b00110000},{
// /
0b00000000,
0b00000000,
0b00001000,
0b00010000,
0b00100000,
0b01000000,
0b10000000
}};
static const unsigned char PROGMEM logo_bp[][24] = {{//動畫點陣圖
0b00011111, 0b11111000,
0b00011111, 0b11111000,
0b00011000, 0b00011000,
0b00011000, 0b00011000,
0b00011111, 0b11111000,
0b00011111, 0b11111000,
0b00011000, 0b00011000,
0b00011000, 0b00011000,
0b00011000, 0b00011000,
0b00011000, 0b00011000,
0b00011111, 0b11111000,
0b00011000, 0b00011000},{
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b01111111, 0b11111110,
0b01111111, 0b11111110,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b00000000, 0b00000000},{
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b00111111, 0b11111100,
0b00111111, 0b11111100,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b01111111, 0b11111110,
0b01111111, 0b11111110,
0b00000000, 0b00000000},{
0b00000000, 0b00000000,
0b00111111, 0b11111100,
0b00111111, 0b11111100,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b00011111, 0b11111000,
0b00011111, 0b11111000,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b01111111, 0b11111110,
0b01111111, 0b11111110},{
0b00111111, 0b11111110,
0b00110011, 0b01100110,
0b00110011, 0b01100110,
0b00110011, 0b01100110,
0b00110011, 0b01100110,
0b00110011, 0b01100110,
0b00110011, 0b01110110,
0b00110110, 0b00111110,
0b00111000, 0b00000110,
0b00110000, 0b00000110,
0b00111111, 0b11111110,
0b00111111, 0b11111110},{
0b01111111, 0b11111100,
0b01111111, 0b11111100,
0b00000011, 0b00000000,
0b00000011, 0b00000000,
0b00111111, 0b11110000,
0b00111111, 0b11110000,
0b00001100, 0b00110000,
0b00001100, 0b00110000,
0b00011000, 0b00110000,
0b00011000, 0b00110000,
0b11111111, 0b11111110,
0b11111111, 0b11111110},{
0b00000011, 0b00000000,
0b00000001, 0b10000000,
0b00000001, 0b10000000,
0b00000000, 0b00000000,
0b00000000, 0b00000000,
0b01111111, 0b11111110,
0b01111111, 0b11111110,
0b00000000, 0b00000000,
0b00001100, 0b00110000,
0b00011000, 0b00011000,
0b00110000, 0b00001100,
0b01100000, 0b00000110
}};
void setup() {
// 打開串行通訊並等待連接埠開啟:
Serial.begin(9600);
// 等待串行監視器連接。 僅本機 USB 連接埠板需要:
while (!Serial);
if (!SD.begin(chipSelect)) while (true);
// 開啟檔案。 請注意,一次只能開啟一個文件,
// 所以你必須在打開另一個之前關閉這個。
myFile = SD.open("wokwi.txt", FILE_WRITE);
// 如果檔案開啟正常,則寫入:
if (myFile) {
Serial.println("寫入:...");myFile.
println("");
myFile.println("\ntesting \t1, 2, 3.");
// 關閉檔案:
myFile.close();
Serial.println("完畢.");
} else {
// 如果文件未打開,則列印錯誤:
Serial.println("開啟時出錯");
}
// 重新開啟檔案進行讀取:
myFile = SD.open("wokwi.txt");
if (myFile) {
Serial.println("wokwi.txt:");
// 從文件中讀取,直到其中沒有其他內容為止:
while (myFile.available()) {
Serial.write(myFile.read());
}
// 關閉文件:
myFile.close();
} else {
//如果文件未打開,則列印錯誤:
Serial.println("開啟時出錯");
}
if (!htu.begin()) Serial.println(F("HTU21D Fall"));
if (! rtc.begin()) {
Serial.println("NA RTC");
Serial.flush();
abort();
}
u8g.setFont(u8g_font_tpssb);
u8g.setColorIndex(1);
}
void loop() {
DateTime now = rtc.now();
u8g.firstPage();
do {
//u8g.setFont(u8g_font_ncenR10);
//u8g.drawStr(5, 14, "2024/03/10");
//u8g.drawStr(1, 45, "12:34");
//u8g.drawStr(1, 64, "25 70");
u8g.drawFrame(3, 17, 122, 6);
u8g.drawBox(5, 19, progress * 2, 2);
u8g.drawBitmapP(49,45,2,12,logo_bp[progress / 8]);
u8g.drawBitmapP( 68 , 45 , 1 , 7 , logo_bq[progress % 10] );
/*
u8g.drawFrame(78, 38, 12, 8);
u8g.drawBitmapP( 80, 40 ,1, 4,Pqe_4[0]);
u8g.drawBitmapP( 95, 40 ,1, 4,Pqe_4[1]);
u8g.drawBitmapP( 80, 50 ,1, 4,Pqe_4[2]);
u8g.drawBitmapP( 95, 50 ,1, 4,Pqe_4[3]);
*/
u8g.drawFrame(78, 24, 36, 32);
LCD_4( 80 , 26 , progress % 10 );
} while ( u8g.nextPage() );
if (progress < 59 ) {
progress++;
} else {
progress = 0;
}
}
void LCD_4(int X,int y,int arr){
Serial.println();
Serial.print(arr);
for (int i = 0; i < 7 ; i++) {
Serial.println();
Serial.print("H");
Serial.print(i);
Serial.print("I");
char b = logo_bq[arr][i];
Serial.print((int)b);
Serial.print("//");
for(int j = 3; j > -1; j--){
char a = 0X03;
char c = a & b;
Serial.print((int)b);
Serial.print(";");
Serial.print((int)c);
Serial.print(".");
b = b >> 2;
u8g.drawBitmapP( X +j* 8, y + i * 4 ,1, 4,Pqe_4[c]);
}
}
}