-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolarCharger.ino
executable file
·65 lines (51 loc) · 1.54 KB
/
SolarCharger.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
#include "src/ACSReader.cpp"
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
#define OLED_RESET 4
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
ACSReader acsr(5.06, A0, 3.2, 1023, 100);
int infoDelay = 0;
void setup() {
Serial.begin(9600);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
Serial.println("SSD1306 allocation failed!");
}
display.display();
delay(2000);
display.clearDisplay();
display.display();
acsr.acs.autoMidPoint();
}
void loop() {
float mA = acsr.getMedianDC(10, 100);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
Serial.println("SSD1306 allocation failed");
} else {
char toPrint[21];
snprintf(toPrint, 21, "A: %dmA\nW: %.02fW", (int)mA, acsr.getWatt());
printDisplay(toPrint);
delay(1000);
if (infoDelay > 4) {
snprintf(toPrint, 21, "Runtime:\n%s", acsr.getWorkingTime());
printDisplay(toPrint);
delay(3000);
snprintf(toPrint, 21, "Supplied:\n%s", acsr.getSuppliedWattString());
printDisplay(toPrint);
delay(3000);
infoDelay = 0;
} else {
infoDelay++;
}
}
}
void printDisplay(const char* str) {
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print(str);
display.display();
}