POczatek mierzenia baterii
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
#define BTN_UP 33
|
#define BTN_UP 33
|
||||||
#define BTN_ENTER 34
|
#define BTN_ENTER 34
|
||||||
#define BTN_DOWN 35
|
#define BTN_DOWN 35
|
||||||
|
#define VOLT_IN 36
|
||||||
|
|
||||||
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &WIRE);
|
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &WIRE);
|
||||||
DHT dht(DHTPIN, DHTTYPE);
|
DHT dht(DHTPIN, DHTTYPE);
|
||||||
@@ -41,11 +42,15 @@ int years;
|
|||||||
int minsToSet = -1;
|
int minsToSet = -1;
|
||||||
int hoursToSet = -1;
|
int hoursToSet = -1;
|
||||||
|
|
||||||
|
int adcVoltValue;
|
||||||
|
|
||||||
char dateString[21];
|
char dateString[21];
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Wire.begin(21, 22);
|
Wire.begin(21, 22);
|
||||||
|
analogSetAttenuation(ADC_11db);
|
||||||
|
|
||||||
if (!rtc.begin()) {
|
if (!rtc.begin()) {
|
||||||
Serial.println("Nie znaleziono DS3231 RTC!");
|
Serial.println("Nie znaleziono DS3231 RTC!");
|
||||||
while (1); // Zatrzymaj program, jeśli RTC nie jest dostępny
|
while (1); // Zatrzymaj program, jeśli RTC nie jest dostępny
|
||||||
@@ -62,7 +67,7 @@ void setup() {
|
|||||||
display.setCursor(32, 16);
|
display.setCursor(32, 16);
|
||||||
display.println("RTC: DS3231");
|
display.println("RTC: DS3231");
|
||||||
display.setCursor(0, 24);
|
display.setCursor(0, 24);
|
||||||
display.println("Battery: 19int");
|
display.println("Battery: 18h");
|
||||||
display.display();
|
display.display();
|
||||||
delay(500);
|
delay(500);
|
||||||
dht.begin();
|
dht.begin();
|
||||||
@@ -70,26 +75,31 @@ void setup() {
|
|||||||
pinMode(BTN_ENTER, INPUT_PULLDOWN );
|
pinMode(BTN_ENTER, INPUT_PULLDOWN );
|
||||||
pinMode(BTN_DOWN, INPUT_PULLDOWN );
|
pinMode(BTN_DOWN, INPUT_PULLDOWN );
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.setCursor(0, 8);
|
display.setCursor(0,0);
|
||||||
if (!SD.begin(SD_CS)) {
|
if (!SD.begin(SD_CS)) {
|
||||||
display.println("Błąd inicjalizacji karty SD!");
|
display.println("Blad inicjaliz SD!");
|
||||||
return;
|
display.display();
|
||||||
}
|
delay(1000);
|
||||||
Serial.println("Karta SD wykryta!");
|
}else {
|
||||||
// Tworzenie pliku
|
Serial.println("Karta SD wykryta!");
|
||||||
File file = SD.open("/dane.txt", FILE_WRITE);
|
}
|
||||||
if (file) {
|
|
||||||
file.println("Dane zapisane z ESP32!");
|
|
||||||
file.close();
|
|
||||||
display.println("Plik utworzony!");
|
|
||||||
|
|
||||||
} else {
|
|
||||||
display.println("Błąd zapisu pliku!");
|
display.setCursor(0,16);
|
||||||
|
// Tworzenie pliku
|
||||||
}
|
File file = SD.open("/dane.txt", FILE_WRITE);
|
||||||
display.display();
|
if (file) {
|
||||||
delay(1500);
|
file.println("Dane zapisane z ESP32!");
|
||||||
|
file.close();
|
||||||
|
display.println("Plik utworzony!");
|
||||||
|
|
||||||
|
} else {
|
||||||
|
display.println("Blad zapisu pliku!");
|
||||||
|
display.display();
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
display.display();
|
||||||
|
delay(500);
|
||||||
//setup END
|
//setup END
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,19 +277,25 @@ void loop() {
|
|||||||
|
|
||||||
if (menuL0 == 9 ) {
|
if (menuL0 == 9 ) {
|
||||||
display.setCursor(0, 0);
|
display.setCursor(0, 0);
|
||||||
display.print("MENU2");
|
display.print("MENU TECH");
|
||||||
|
adcVoltValue = analogRead(VOLT_IN); // Odczyt wartości ADC z GPIO36
|
||||||
|
display.setCursor(0,8);
|
||||||
|
display.print("ADC:");
|
||||||
|
display.setCursor(20, 24);
|
||||||
|
display.print(adcVoltValue);
|
||||||
|
|
||||||
|
Serial.println(adcVoltValue);
|
||||||
|
|
||||||
if (digitalRead(BTN_UP) == HIGH) {
|
if (digitalRead(BTN_UP) == HIGH) {
|
||||||
display.setCursor(0, 8);
|
display.setCursor(0, 24);
|
||||||
display.print("UP");
|
display.print("UP");
|
||||||
}
|
}
|
||||||
if (digitalRead(BTN_ENTER) == HIGH) {
|
if (digitalRead(BTN_ENTER) == HIGH) {
|
||||||
display.setCursor(30, 8);
|
display.setCursor(30, 24);
|
||||||
display.print("ENTER");
|
display.print("ENTER");
|
||||||
}
|
}
|
||||||
if (digitalRead(BTN_DOWN) == HIGH) {
|
if (digitalRead(BTN_DOWN) == HIGH) {
|
||||||
display.setCursor(60, 8);
|
display.setCursor(60, 24);
|
||||||
display.print("DOWN");
|
display.print("DOWN");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -332,6 +348,29 @@ void loop() {
|
|||||||
delay(150);
|
delay(150);
|
||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
|
//
|
||||||
|
//float interpolate(float x, float x0, float x1, float y0, float y1) {
|
||||||
|
// return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//// Funkcja przeliczająca zmierzone napięcie na procent naładowania
|
||||||
|
//float voltageToPercentage(float voltage) {
|
||||||
|
// // Jeśli napięcie jest poniżej minimalnego punktu – bateria uznajemy za rozładowaną
|
||||||
|
// if (voltage <= voltagePoints[0])
|
||||||
|
// return percentPoints[0];
|
||||||
|
// // Jeśli napięcie przekracza najwyższy punkt – bateria jest pełna
|
||||||
|
// if (voltage >= voltagePoints[numPoints - 1])
|
||||||
|
// return percentPoints[numPoints - 1];
|
||||||
|
//
|
||||||
|
// // Szukamy przedziału, w którym mieści się zmierzone napięcie, i stosujemy interpolację
|
||||||
|
// for (int i = 0; i < numPoints - 1; i++) {
|
||||||
|
// if (voltage >= voltagePoints[i] && voltage < voltagePoints[i+1]) {
|
||||||
|
// return interpolate(voltage, voltagePoints[i], voltagePoints[i+1], percentPoints[i], percentPoints[i+1]);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return 0;
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
//Main feature:
|
//Main feature:
|
||||||
// RTC z możliwością ustawienia godziny
|
// RTC z możliwością ustawienia godziny
|
||||||
|
|||||||
Reference in New Issue
Block a user