POczatek mierzenia baterii
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#define BTN_UP 33
|
||||
#define BTN_ENTER 34
|
||||
#define BTN_DOWN 35
|
||||
#define VOLT_IN 36
|
||||
|
||||
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &WIRE);
|
||||
DHT dht(DHTPIN, DHTTYPE);
|
||||
@@ -41,11 +42,15 @@ int years;
|
||||
int minsToSet = -1;
|
||||
int hoursToSet = -1;
|
||||
|
||||
int adcVoltValue;
|
||||
|
||||
char dateString[21];
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Wire.begin(21, 22);
|
||||
analogSetAttenuation(ADC_11db);
|
||||
|
||||
if (!rtc.begin()) {
|
||||
Serial.println("Nie znaleziono DS3231 RTC!");
|
||||
while (1); // Zatrzymaj program, jeśli RTC nie jest dostępny
|
||||
@@ -62,7 +67,7 @@ void setup() {
|
||||
display.setCursor(32, 16);
|
||||
display.println("RTC: DS3231");
|
||||
display.setCursor(0, 24);
|
||||
display.println("Battery: 19int");
|
||||
display.println("Battery: 18h");
|
||||
display.display();
|
||||
delay(500);
|
||||
dht.begin();
|
||||
@@ -70,26 +75,31 @@ void setup() {
|
||||
pinMode(BTN_ENTER, INPUT_PULLDOWN );
|
||||
pinMode(BTN_DOWN, INPUT_PULLDOWN );
|
||||
display.clearDisplay();
|
||||
display.setCursor(0, 8);
|
||||
display.setCursor(0,0);
|
||||
if (!SD.begin(SD_CS)) {
|
||||
display.println("Błąd inicjalizacji karty SD!");
|
||||
return;
|
||||
}
|
||||
Serial.println("Karta SD wykryta!");
|
||||
// Tworzenie pliku
|
||||
File file = SD.open("/dane.txt", FILE_WRITE);
|
||||
if (file) {
|
||||
file.println("Dane zapisane z ESP32!");
|
||||
file.close();
|
||||
display.println("Plik utworzony!");
|
||||
display.println("Blad inicjaliz SD!");
|
||||
display.display();
|
||||
delay(1000);
|
||||
}else {
|
||||
Serial.println("Karta SD wykryta!");
|
||||
}
|
||||
|
||||
} else {
|
||||
display.println("Błąd zapisu pliku!");
|
||||
|
||||
}
|
||||
display.display();
|
||||
delay(1500);
|
||||
|
||||
display.setCursor(0,16);
|
||||
// Tworzenie pliku
|
||||
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("Blad zapisu pliku!");
|
||||
display.display();
|
||||
delay(1000);
|
||||
}
|
||||
display.display();
|
||||
delay(500);
|
||||
//setup END
|
||||
}
|
||||
|
||||
@@ -267,19 +277,25 @@ void loop() {
|
||||
|
||||
if (menuL0 == 9 ) {
|
||||
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) {
|
||||
display.setCursor(0, 8);
|
||||
display.setCursor(0, 24);
|
||||
display.print("UP");
|
||||
}
|
||||
if (digitalRead(BTN_ENTER) == HIGH) {
|
||||
display.setCursor(30, 8);
|
||||
display.setCursor(30, 24);
|
||||
display.print("ENTER");
|
||||
}
|
||||
if (digitalRead(BTN_DOWN) == HIGH) {
|
||||
display.setCursor(60, 8);
|
||||
display.setCursor(60, 24);
|
||||
display.print("DOWN");
|
||||
}
|
||||
}
|
||||
@@ -332,6 +348,29 @@ void loop() {
|
||||
delay(150);
|
||||
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:
|
||||
// RTC z możliwością ustawienia godziny
|
||||
|
||||
Reference in New Issue
Block a user