Menu ustawiania czasu.
This commit is contained in:
@@ -9,15 +9,12 @@
|
||||
#include "SD.h"
|
||||
#include "SPI.h"
|
||||
|
||||
|
||||
|
||||
#define Version "menu : 0.2"
|
||||
#define Version "menu : 0.1menu"
|
||||
#define WIRE Wire
|
||||
#define DHTTYPE DHT22
|
||||
#define DHTPIN 4
|
||||
#define DHTPIN 4
|
||||
#define SD_CS 5
|
||||
|
||||
|
||||
#define BTN_UP 33
|
||||
#define BTN_ENTER 34
|
||||
#define BTN_DOWN 35
|
||||
@@ -25,37 +22,34 @@
|
||||
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &WIRE);
|
||||
DHT dht(DHTPIN, DHTTYPE);
|
||||
RTC_DS3231 rtc; // Obiekt dla DS3231
|
||||
int menu =10;
|
||||
int menuL0 = 10;
|
||||
int menuL1 = 10;
|
||||
int menuL2 = 10;
|
||||
|
||||
float hum;
|
||||
float temp;
|
||||
float heat_idx;
|
||||
|
||||
|
||||
int mins;
|
||||
int secs;
|
||||
int mins;
|
||||
int hourss;
|
||||
int dayss;
|
||||
int months;
|
||||
int years;
|
||||
|
||||
int minsToSet = -1;
|
||||
int hoursToSet = -1;
|
||||
|
||||
char dateString[21];
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
|
||||
Wire.begin(21, 22);
|
||||
Wire.begin(21, 22);
|
||||
if (!rtc.begin()) {
|
||||
Serial.println("Nie znaleziono DS3231 RTC!");
|
||||
while (1); // Zatrzymaj program, jeśli RTC nie jest dostępny
|
||||
}
|
||||
|
||||
//Ustawianie daty i godziny:
|
||||
// rtc.adjust(DateTime(2025, 2, 10, 20, 35, 30));
|
||||
|
||||
|
||||
|
||||
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(SSD1306_WHITE);
|
||||
@@ -65,56 +59,57 @@ void setup() {
|
||||
display.println(Version);
|
||||
display.setCursor(0, 16);
|
||||
display.println("DHT22");
|
||||
display.setCursor(0, 24);
|
||||
display.setCursor(32, 16);
|
||||
display.println("RTC: DS3231");
|
||||
|
||||
display.setCursor(0, 24);
|
||||
display.println("Battery: 19int");
|
||||
display.display();
|
||||
delay(500);
|
||||
dht.begin();
|
||||
pinMode(BTN_UP, INPUT_PULLDOWN );
|
||||
pinMode(BTN_ENTER, INPUT_PULLDOWN );
|
||||
pinMode(BTN_DOWN, INPUT_PULLDOWN );
|
||||
|
||||
display.clearDisplay();
|
||||
display.setCursor(0,8);
|
||||
|
||||
display.setCursor(0, 8);
|
||||
if (!SD.begin(SD_CS)) {
|
||||
display.println("Błąd inicjalizacji karty SD!");
|
||||
return;
|
||||
}
|
||||
Serial.println("Karta SD wykryta!");
|
||||
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!");
|
||||
|
||||
// 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("Błąd zapisu pliku!");
|
||||
|
||||
} else {
|
||||
display.println("Błąd zapisu pliku!");
|
||||
}
|
||||
display.display();
|
||||
delay(1500);
|
||||
|
||||
}
|
||||
display.display();
|
||||
delay(1500);
|
||||
|
||||
//setup END
|
||||
//setup END
|
||||
}
|
||||
|
||||
void loop() {
|
||||
display.clearDisplay();
|
||||
|
||||
////DIAG menu nr diag
|
||||
// display.setCursor(75, 16);
|
||||
// display.println(menuL0);
|
||||
// display.setCursor(90, 16);
|
||||
// display.println(menuL1);
|
||||
// display.setCursor(105, 16);
|
||||
// display.println(menuL2);
|
||||
|
||||
hum = dht.readHumidity();
|
||||
temp = dht.readTemperature();
|
||||
// Compute heat index in Celsius (isFahreheit = false)
|
||||
heat_idx = dht.computeHeatIndex(temp, hum, false);
|
||||
|
||||
|
||||
|
||||
//DATE
|
||||
DateTime now = rtc.now();
|
||||
|
||||
//DATE
|
||||
DateTime now = rtc.now();
|
||||
years = now.year();
|
||||
months = now.month();
|
||||
dayss = now.day();
|
||||
@@ -122,80 +117,225 @@ void loop() {
|
||||
mins = now.minute();
|
||||
secs = now.second();
|
||||
|
||||
|
||||
if (menu == 10 ){
|
||||
// ############# MENU TEMP
|
||||
if (menuL0 == 10 ) {
|
||||
// ############# MENU TEMP
|
||||
sprintf(dateString, "%02d/%02d/%4d %02d:%02d:%02d", now.day(), now.month(), now.year(), now.hour(), now.minute(), now.second());
|
||||
display.setCursor(0,0);
|
||||
display.println(dateString);
|
||||
//HUM&TEMP
|
||||
//#########################################
|
||||
display.setCursor(0,8);
|
||||
display.setCursor(0, 0);
|
||||
display.println(dateString);
|
||||
|
||||
//HUM&TEMP
|
||||
//#########################################
|
||||
display.setCursor(0, 8);
|
||||
display.println("Wilgotnosc:");
|
||||
display.setCursor(85,8);
|
||||
display.setCursor(85, 8);
|
||||
display.println(hum);
|
||||
display.setCursor(120,8);
|
||||
display.setCursor(120, 8);
|
||||
display.println("%");
|
||||
|
||||
display.setCursor(0,16);
|
||||
|
||||
display.setCursor(0, 16);
|
||||
display.println("Temperatura:");
|
||||
display.setCursor(85,16);
|
||||
display.setCursor(85, 16);
|
||||
display.println(temp);
|
||||
display.setCursor(120,16);
|
||||
display.println("C");
|
||||
|
||||
display.setCursor(0,24);
|
||||
|
||||
display.setCursor(0, 24);
|
||||
display.println("Odczuwalna:");
|
||||
display.setCursor(85,24);
|
||||
display.println(heat_idx);
|
||||
display.setCursor(120,24);
|
||||
display.println("C");
|
||||
}
|
||||
display.setCursor(85, 24);
|
||||
display.println(heat_idx);
|
||||
display.setCursor(120,24);
|
||||
display.println("C");
|
||||
}
|
||||
|
||||
|
||||
|
||||
//dla indexu: Caution: > 27*C
|
||||
// Extreme Caution: > 32 *C
|
||||
// Danger: > 40 *C
|
||||
// Extreme Danger: > 52 *C
|
||||
//#########################################
|
||||
|
||||
if (menu == 9 ){
|
||||
display.setCursor(0,0);
|
||||
display.print("MENU2");
|
||||
|
||||
//dla indexu: Caution: > 27*C
|
||||
// Extreme Caution: > 32 *C
|
||||
// Danger: > 40 *C
|
||||
// Extreme Danger: > 52 *C
|
||||
//#########################################
|
||||
|
||||
|
||||
|
||||
if (menuL0 == 8 ) {
|
||||
if (digitalRead(BTN_ENTER) == HIGH and menuL1 == 10) {
|
||||
menuL1 = 9;
|
||||
}
|
||||
display.setCursor(0, 0);
|
||||
sprintf(dateString, "%02d/%02d/%4d %02d:%02d:%02d", now.day(), now.month(), now.year(), now.hour(), now.minute(), now.second());
|
||||
display.println(dateString);
|
||||
if (menuL1 == 10) {
|
||||
display.setCursor(0, 8);
|
||||
display.print("Enter edycja czasu");
|
||||
|
||||
}
|
||||
if (menuL1 == 9) {
|
||||
display.setCursor(0, 8);
|
||||
delay(100);
|
||||
display.print("Ustaw godziny");
|
||||
delay(150);
|
||||
if (digitalRead(BTN_ENTER) == HIGH and menuL2 == 10) {
|
||||
menuL2 = 9;
|
||||
}
|
||||
|
||||
if (menuL2 == 9){
|
||||
display.setCursor(0,16);
|
||||
display.print("Godzina:");
|
||||
display.setCursor(45,16);
|
||||
if (hoursToSet == -1){
|
||||
hoursToSet = now.hour();
|
||||
}
|
||||
display.print(hoursToSet);
|
||||
delay(100);
|
||||
|
||||
if (digitalRead(BTN_ENTER) == HIGH) {
|
||||
// tu ustawianie czasu
|
||||
menuL2 = 10;
|
||||
rtc.adjust(DateTime(now.year(), now.month(), now.day(), hoursToSet, now.minute(), now.second()));
|
||||
hoursToSet = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (menuL1 == 8) {
|
||||
display.setCursor(0, 8);
|
||||
display.print("Ustaw minuty");
|
||||
|
||||
if (digitalRead(BTN_ENTER) == HIGH and menuL2 == 10) {
|
||||
menuL2 = 9;
|
||||
}
|
||||
|
||||
if (menuL2 == 9){
|
||||
display.setCursor(0,16);
|
||||
display.print("Minuta:");
|
||||
display.setCursor(45,16);
|
||||
if (minsToSet == -1){
|
||||
minsToSet = now.minute();
|
||||
}
|
||||
display.print(minsToSet);
|
||||
delay(250);
|
||||
|
||||
if (digitalRead(BTN_ENTER) == HIGH) {
|
||||
// tu ustawianie czasu
|
||||
menuL2 = 10;
|
||||
rtc.adjust(DateTime(now.year(), now.month(), now.day(), now.hour(), minsToSet, now.second()));
|
||||
minsToSet = -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (menuL2 == 6){
|
||||
|
||||
display.setCursor(0,24);
|
||||
display.print("Wyjdz");
|
||||
if (digitalRead(BTN_ENTER) == HIGH) {
|
||||
menuL2 = 10;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if (menuL1 == 7 ) {
|
||||
display.setCursor(0, 8);
|
||||
display.print("Ustaw sekundy na 0");
|
||||
|
||||
|
||||
if (digitalRead(BTN_ENTER) == HIGH and menuL2 == 10) {
|
||||
menuL2 = 9;
|
||||
}
|
||||
|
||||
if (menuL2 == 9){
|
||||
display.setCursor(0,16);
|
||||
display.print("Sekundy = 0");
|
||||
delay(250);
|
||||
if (digitalRead(BTN_ENTER) == HIGH) {
|
||||
menuL2 = 10;
|
||||
rtc.adjust(DateTime(now.year(), now.month(), now.day(), now.hour(), now.minute(),0));
|
||||
minsToSet = -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (digitalRead(BTN_UP) == HIGH) {
|
||||
display.setCursor(0,8);
|
||||
display.print("UP");
|
||||
if (menuL1 == 6) {
|
||||
display.setCursor(0, 8);
|
||||
display.print("Wyjdz");
|
||||
if (digitalRead(BTN_ENTER) == HIGH) {
|
||||
menuL1 = 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (digitalRead(BTN_ENTER) == HIGH) {
|
||||
display.setCursor(30,8);
|
||||
display.print("ENTER");
|
||||
}
|
||||
if (digitalRead(BTN_DOWN) == HIGH) {
|
||||
display.setCursor(60,8);
|
||||
display.print("DOWN");
|
||||
|
||||
if (menuL0 == 9 ) {
|
||||
display.setCursor(0, 0);
|
||||
display.print("MENU2");
|
||||
|
||||
|
||||
if (digitalRead(BTN_UP) == HIGH) {
|
||||
display.setCursor(0, 8);
|
||||
display.print("UP");
|
||||
}
|
||||
if (digitalRead(BTN_ENTER) == HIGH) {
|
||||
display.setCursor(30, 8);
|
||||
display.print("ENTER");
|
||||
}
|
||||
if (digitalRead(BTN_DOWN) == HIGH) {
|
||||
display.setCursor(60, 8);
|
||||
display.print("DOWN");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (digitalRead(BTN_UP) == HIGH and menuL0 <10 ) {
|
||||
if ( menuL0 < 10 && menuL1 == 10 ) {
|
||||
menuL0 = menuL0 + 1;
|
||||
}
|
||||
if (menuL1 < 9 && menuL2 == 10) {
|
||||
menuL1 = menuL1 + 1;
|
||||
}
|
||||
if (menuL2 < 9 and menuL0 != 10 and menuL1 != 10) {
|
||||
menuL2 = menuL2 + 1;
|
||||
}
|
||||
if (menuL2 == 9 and minsToSet <59)
|
||||
{
|
||||
minsToSet = minsToSet + 1;
|
||||
}
|
||||
if (menuL2 == 9 and hoursToSet < 23)
|
||||
{
|
||||
hoursToSet = hoursToSet + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (digitalRead(BTN_DOWN) == HIGH and menuL0 >= 8) {
|
||||
if (menuL0 > 8 && menuL1 == 10 ) {
|
||||
menuL0 = menuL0 - 1;
|
||||
}
|
||||
if (menuL1 > 6 and menuL1 <= 9 && menuL2 == 10) {
|
||||
menuL1 = menuL1 - 1;
|
||||
}
|
||||
if (menuL2 > 6 and menuL2 < 9 and menuL0 != 10 and menuL1 != 10 ) {
|
||||
menuL2 = menuL2 - 1;
|
||||
}
|
||||
if (menuL2 == 9 and minsToSet > 1)
|
||||
{
|
||||
minsToSet = minsToSet - 1;
|
||||
}
|
||||
if (menuL2 == 9 and hoursToSet > 1)
|
||||
{
|
||||
hoursToSet = hoursToSet - 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (menu == 8 ){
|
||||
display.setCursor(0,0);
|
||||
display.print("MENU testowe");
|
||||
}
|
||||
|
||||
|
||||
display.display();
|
||||
delay(500);
|
||||
|
||||
if (digitalRead(BTN_UP) == HIGH and menu <10 ) {
|
||||
menu = menu +1;
|
||||
}
|
||||
|
||||
if (digitalRead(BTN_DOWN) == HIGH and menu > 8) {
|
||||
menu = menu -1;
|
||||
}
|
||||
|
||||
|
||||
display.display();
|
||||
delay(150);
|
||||
yield();
|
||||
}
|
||||
|
||||
//Main feature:
|
||||
// RTC z możliwością ustawienia godziny
|
||||
// odczyt wilgotności, temperatury i temperatury odcuwalnej
|
||||
// zasilanie bateryjne
|
||||
// menu
|
||||
//2DO zapis na karcie SD
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user