-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOled_Yt_Info.ino
183 lines (148 loc) · 5.93 KB
/
Oled_Yt_Info.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <YoutubeApi.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
char ssid[] = "XXX";
char password[] = "XXX";
#define YT_DATA_API_KEY "XXX"
#define YT_CHANNEL_ID "XXX"
WiFiClientSecure client;
YoutubeApi api(YT_DATA_API_KEY, client);
unsigned long previousMillis = 0;
unsigned long displayDuration = 5000; // Her gösterim süresi 5 saniye
unsigned long stageDuration = 5000; // Aşamaların süresi 5 saniye
unsigned long apiInterval = 30 * 60 * 1000; // 30 dakika (30 * 60 * 1000 ms)
unsigned long lastApiCallTime = 0; // Son API çağrısının zamanı
int stage = 0; // Gösterim aşaması (0: logo, 1: abone, 2: izlenme, 3: video sayısı)
unsigned long stageStartTime = 0; // Aşamaların başladığı zaman
const unsigned char myBitmap[] PROGMEM = {
// YouTube logosunun bitmap verisi burada olacak.
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xf8, 0x3f, 0xff, 0xff, 0xfc, 0x7f, 0xff, 0xff, 0xfe,
0x7f, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfb, 0xff, 0xff,
0xff, 0xf8, 0xff, 0xff, 0xff, 0xf8, 0x7f, 0xff, 0xff, 0xf8, 0x1f, 0xff, 0xff, 0xf8, 0x07, 0xff,
0xff, 0xf8, 0x0f, 0xff, 0xff, 0xf8, 0x3f, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0xfb, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xfe,
0x7f, 0xff, 0xff, 0xfe, 0x3f, 0xff, 0xff, 0xfc, 0x1f, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void setup() {
Serial.begin(115200);
Wire.begin(0, 2);
client.setInsecure();
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
for (;;)
; // SSD1306 başlatılamazsa sonsuza kadar bekle
}
display.clearDisplay();
display.display();
display.setCursor(0, 0);
display.setTextColor(WHITE);
display.print("Connecting WiFi: ");
display.print(ssid);
display.display();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
display.print(".");
display.display();
delay(500);
}
display.clearDisplay();
display.setCursor(0, 0);
display.println("WiFi connected.");
display.println("IP address: ");
IPAddress ip = WiFi.localIP();
display.println(ip);
display.display();
// İlk veri çekme
fetchDataFromApi();
stageStartTime = millis(); // İlk aşamanın başlangıç zamanını ayarla
}
void fetchDataFromApi() {
if (api.getChannelStatistics(YT_CHANNEL_ID)) {
// API'den veri başarılı bir şekilde alındığında debug mesajı kaldırıldı
} else {
// API'den veri alınamadığında herhangi bir işlem yapılmaz
}
lastApiCallTime = millis(); // API çağrısının zamanını güncelle
}
int getTextWidth(String text) {
return text.length() * 6; // SSD1306 font uzunluğunun 6 piksel olduğunu varsayıyoruz
}
void loop() {
unsigned long currentMillis = millis();
// 30 dakikada bir API'den veri çekmek için zaman kontrolü
if (currentMillis - lastApiCallTime >= apiInterval) {
fetchDataFromApi(); // API'den veri çek
}
if (currentMillis - stageStartTime >= stageDuration) {
// 5 saniye tamamlandığında, aşamayı değiştir
stageStartTime = currentMillis; // Aşamayı sıfırla
if (stage == 0) {
// Logo gösterimi
stage = 1; // Logo sonrası abone sayısına geç
} else if (stage == 1) {
// Abone sayısı gösterimi
stage = 2; // Abone sayısı sonrası izlenme sayısına geç
} else if (stage == 2) {
// İzlenme sayısı gösterimi
stage = 3; // İzlenme sayısı sonrası video sayısına geç
} else if (stage == 3) {
// Video sayısı gösterimi
stage = 1; // Video sayısı sonrası abone sayısına geri dön
}
}
display.clearDisplay(); // Her seferinde ekranı temizle
if (stage == 0) {
// Logo gösterimi
int xPos = (SCREEN_WIDTH - 32) / 2; // Bitmap'in yatayda ortalanacağı x konumu
int yPos = (SCREEN_HEIGHT - 32) / 2; // Bitmap'in dikeyde ortalanacağı y konumu
display.drawBitmap(xPos, yPos, myBitmap, 32, 32, WHITE);
display.display();
} else if (stage == 1) {
// Abone sayısını göster
String subscriberCount = String(api.channelStats.subscriberCount);
String title = "ABONE SAYISI";
int titleWidth = getTextWidth(title);
int valueWidth = getTextWidth(subscriberCount);
int titleXPos = (SCREEN_WIDTH - titleWidth) / 2;
int valueXPos = (SCREEN_WIDTH - valueWidth) / 2;
display.setCursor(titleXPos, 10);
display.println(title);
display.setCursor(valueXPos, 20);
display.println(subscriberCount);
display.display();
} else if (stage == 2) {
// İzlenme sayısını göster
String viewCount = String(api.channelStats.viewCount);
String title = "IZLENME SAYISI";
int titleWidth = getTextWidth(title);
int valueWidth = getTextWidth(viewCount);
int titleXPos = (SCREEN_WIDTH - titleWidth) / 2;
int valueXPos = (SCREEN_WIDTH - valueWidth) / 2;
display.setCursor(titleXPos, 10);
display.println(title);
display.setCursor(valueXPos, 20);
display.println(viewCount);
display.display();
} else if (stage == 3) {
// Video sayısını göster
String videoCount = String(api.channelStats.videoCount);
String title = "VIDEO SAYISI";
int titleWidth = getTextWidth(title);
int valueWidth = getTextWidth(videoCount);
int titleXPos = (SCREEN_WIDTH - titleWidth) / 2;
int valueXPos = (SCREEN_WIDTH - valueWidth) / 2;
display.setCursor(titleXPos, 10);
display.println(title);
display.setCursor(valueXPos, 20);
display.println(videoCount);
display.display();
}
delay(100); // Fazla yüklenmeyi önlemek için kısa bir gecikme
}