-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.ino
183 lines (146 loc) · 5.12 KB
/
Main.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 <Wire.h>
#include <ArduinoJson.h> // V6!
#include <Adafruit_SH110X.h>
#include <Adafruit_GFX.h>
#include "images.h"
/*
* Don't rate this code! It's a project for fun :)
*/
/*
* !!! IMPORTANT This project was developer to work with SSH1106 - 1.3 0.96 128x64 OLED DISPLAY
* Pay atention if you use a diferent display !!
*/
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define SCREEN_ADDRESS 0x3C // Change conform your OLED Display
#if ESP8266
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#define OLED_RESET D4
#endif
#if ESP32
#include <WiFi.h>
#include <HTTPClient.h>
#define OLED_RESET 4
#endif
#define LOGO_HEIGHT 64
#define LOGO_WIDTH 128
Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); // Change conform your OLED Display <<<<<<<<<<<<<
const char *ssid = ""; // Change this to your WiFi SSID <<<<<<<<<<<<<
const char *password = ""; // Change this to your WiFi password <<<<<<<<<<<<<
const String ducoUser = ""; // Change this to your Duino-Coin username <<<<<<<<<<<<<
const String ducoReportJsonUrl = "https://server.duinocoin.com/v2/users/" + ducoUser + "?limit=1";
const int run_in_ms = 60000; // 1 Minute to Start Cicle Again. Is recomended use values upper 5000
float lastAverageHash = 0.0;
float lastTotalHash = 0.0;
#define FRAME_DELAY (42)
#define FRAME_WIDTH (64)
#define FRAME_HEIGHT (64)
#define FRAME_COUNT (sizeof(pigAnimation) / sizeof(pigAnimation[0])) // All animatins as the same size
void DrawPig(void) { // Draw a cash pig animation in display
int i;
for (i = 1; i < 28; ++i)
{
display.clearDisplay();
display.drawBitmap(32, 0, pigAnimation[i], FRAME_WIDTH, FRAME_HEIGHT, 1);
display.display();
delay(FRAME_DELAY);
}
}
void DrawEmojiS(void) { // Draw a emoji animation in display
int i;
for (i = 1; i < 28; ++i)
{
display.clearDisplay();
display.drawBitmap(32, 0, emojiSusto[i], FRAME_WIDTH, FRAME_HEIGHT, 1);
display.display();
delay(FRAME_DELAY);
}
}
void DrawEmojiPiscadaOculos(void) { // Draw a emoji animation in display
int i;
for (i = 1; i < 28; ++i)
{
display.clearDisplay();
display.drawBitmap(32, 0, emojiPiscadaOculos[i], FRAME_WIDTH, FRAME_HEIGHT, 1);
display.display();
delay(FRAME_DELAY);
}
}
void setup() {
Serial.begin(115200);
setupWifi();
delay(250); // wait for the OLED to power up
display.begin(SCREEN_ADDRESS, true); // Address 0x3C default
//display.setContrast (0); // If you need change the constrast set here
display.display();
display.clearDisplay();
}
void loop() {
if (runEvery(run_in_ms)) {
float totalHashrate = 0.0;
float avgHashrate = 0.0;
int total_miner = 0;
String input = httpGetString(ducoReportJsonUrl);
DynamicJsonDocument doc (8000);
DeserializationError error = deserializeJson(doc, input);
if (error) {
Serial.print("deserializeJson() failed: "); // As possible duco server deny your IP with you send a lot requests, be careful
Serial.println(error.c_str());
return;
}
JsonObject result = doc["result"];
JsonObject result_balance = result["balance"];
double result_balance_balance = result_balance["balance"];
const char *result_balance_created = result_balance["created"];
const char *result_balance_username = result_balance["username"];
const char *result_balance_verified = result_balance["verified"];
for (JsonObject result_miner : result["miners"].as<JsonArray>()) {
float result_miner_hashrate = result_miner["hashrate"];
totalHashrate = totalHashrate + result_miner_hashrate;
total_miner++;
}
avgHashrate = totalHashrate / long(total_miner);
long run_span = run_in_ms / 1000;
/*
* Loop >>>
* 1º - Animation Pig
* 2º - Show Miners Number
* 3º - Animation Emoji Blinking
* 4º - Hash Rate Number
* 5º - Animation Emoji Scare
* 6º - Balance Number
*/
DrawPig();
display.clearDisplay();
display.setCursor(4, 0);
display.setTextColor(SH110X_WHITE);
display.setTextSize(2);
display.println("Miners:");
display.setTextSize(3);
display.println(String(total_miner));
display.display();
delay(3000);
display.clearDisplay();
DrawEmojiPiscadaOculos();
display.clearDisplay();
display.setCursor(0, 0);
display.setTextColor(SH110X_WHITE);
display.setTextSize(2);
display.println("Hash Rate:");
display.setTextSize(2);
display.println(String(totalHashrate) + " kH/s");
display.display();
delay(3000);
DrawEmojiS();
display.clearDisplay();
display.setCursor(0, 0);
display.setTextColor(SH110X_WHITE);
display.setTextSize(2);
display.println("Balance:");
display.setTextSize(3);
display.println(String(result_balance_balance));
display.display();
delay(3000);
}
}