Obsługa kart SD- podstawy
obsługa wielu menu i przycisków
This commit is contained in:
@@ -4,16 +4,28 @@
|
||||
#include <Adafruit_SSD1306.h>
|
||||
#include "DHT.h"
|
||||
#include "RTClib.h"
|
||||
//file system
|
||||
#include "FS.h"
|
||||
#include "SD.h"
|
||||
#include "SPI.h"
|
||||
|
||||
#define Version "rtc: 0.7"
|
||||
|
||||
|
||||
#define Version "menu : 0.2"
|
||||
#define WIRE Wire
|
||||
#define DHTTYPE DHT22
|
||||
#define DHTPIN 4
|
||||
#define SD_CS 5
|
||||
|
||||
|
||||
#define BTN_UP 33
|
||||
#define BTN_ENTER 34
|
||||
#define BTN_DOWN 35
|
||||
|
||||
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &WIRE);
|
||||
DHT dht(DHTPIN, DHTTYPE);
|
||||
RTC_DS3231 rtc; // Obiekt dla DS3231
|
||||
|
||||
int menu =10;
|
||||
|
||||
float hum;
|
||||
float temp;
|
||||
@@ -27,9 +39,12 @@ int dayss;
|
||||
int months;
|
||||
int years;
|
||||
char dateString[21];
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
|
||||
Wire.begin(21, 22);
|
||||
if (!rtc.begin()) {
|
||||
Serial.println("Nie znaleziono DS3231 RTC!");
|
||||
@@ -54,14 +69,40 @@ void setup() {
|
||||
display.println("RTC: DS3231");
|
||||
|
||||
display.display();
|
||||
delay(1000);
|
||||
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);
|
||||
|
||||
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!");
|
||||
|
||||
} else {
|
||||
display.println("Błąd zapisu pliku!");
|
||||
|
||||
}
|
||||
display.display();
|
||||
delay(1500);
|
||||
|
||||
//setup END
|
||||
}
|
||||
|
||||
void loop() {
|
||||
delay(1000);
|
||||
display.clearDisplay();
|
||||
|
||||
|
||||
hum = dht.readHumidity();
|
||||
@@ -70,29 +111,47 @@ void loop() {
|
||||
heat_idx = dht.computeHeatIndex(temp, hum, false);
|
||||
|
||||
|
||||
//HUM&TEMP
|
||||
//#########################################
|
||||
display.clearDisplay();
|
||||
display.setCursor(0,0);
|
||||
display.println("Hum:");
|
||||
display.setCursor(60,0);
|
||||
display.println(hum);
|
||||
display.setCursor(95,0);
|
||||
display.println("%");
|
||||
|
||||
display.setCursor(0,8);
|
||||
display.println("Temp:");
|
||||
display.setCursor(60,8);
|
||||
display.println(temp);
|
||||
display.setCursor(95,8);
|
||||
display.println("C");
|
||||
//DATE
|
||||
DateTime now = rtc.now();
|
||||
|
||||
years = now.year();
|
||||
months = now.month();
|
||||
dayss = now.day();
|
||||
hourss = now.hour();
|
||||
mins = now.minute();
|
||||
secs = now.second();
|
||||
|
||||
|
||||
if (menu == 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.println("Wilgotnosc:");
|
||||
display.setCursor(85,8);
|
||||
display.println(hum);
|
||||
display.setCursor(120,8);
|
||||
display.println("%");
|
||||
|
||||
display.setCursor(0,16);
|
||||
display.println("Temp idx:");
|
||||
display.setCursor(60,16);
|
||||
display.println(heat_idx);
|
||||
display.setCursor(95,16);
|
||||
display.println("C");
|
||||
display.setCursor(0,16);
|
||||
display.println("Temperatura:");
|
||||
display.setCursor(85,16);
|
||||
display.println(temp);
|
||||
display.setCursor(120,16);
|
||||
display.println("C");
|
||||
|
||||
display.setCursor(0,24);
|
||||
display.println("Odczuwalna:");
|
||||
display.setCursor(85,24);
|
||||
display.println(heat_idx);
|
||||
display.setCursor(120,24);
|
||||
display.println("C");
|
||||
}
|
||||
|
||||
|
||||
|
||||
//dla indexu: Caution: > 27*C
|
||||
@@ -101,59 +160,42 @@ void loop() {
|
||||
// Extreme Danger: > 52 *C
|
||||
//#########################################
|
||||
|
||||
DateTime now = rtc.now();
|
||||
|
||||
Serial.print(now.year(), DEC);
|
||||
Serial.print('/');
|
||||
Serial.print(now.month(), DEC);
|
||||
Serial.print('/');
|
||||
Serial.print(now.day(), DEC);
|
||||
Serial.print(" ");
|
||||
Serial.print(now.hour(), DEC);
|
||||
Serial.print(':');
|
||||
Serial.print(now.minute(), DEC);
|
||||
Serial.print(':');
|
||||
Serial.print(now.second(), DEC);
|
||||
Serial.println();
|
||||
years = now.year();
|
||||
months = now.month();
|
||||
dayss = now.day();
|
||||
hourss = now.hour();
|
||||
mins = now.minute();
|
||||
secs = now.second();
|
||||
|
||||
// display.setCursor(0,24);
|
||||
// display.println(dayss);
|
||||
// display.setCursor(13,24);
|
||||
// display.println("-");
|
||||
//display.setCursor(20,24);
|
||||
//display.println(months);
|
||||
//display.setCursor(31,24);
|
||||
//display.println("-");
|
||||
//display.setCursor(38,24);
|
||||
//display.println(years);
|
||||
//
|
||||
//
|
||||
// display.setCursor(75,24);
|
||||
// display.println(hourss);
|
||||
// display.setCursor(86,24);
|
||||
// display.println(":");
|
||||
// display.setCursor(92,24);
|
||||
// display.println(mins);
|
||||
// display.setCursor(104,24);
|
||||
// display.println(":");
|
||||
// display.setCursor(109,24);
|
||||
// display.println(secs);
|
||||
|
||||
|
||||
sprintf(dateString, "%02d/%02d/%4d %02d:%02d:%02d", now.day(), now.month(), now.year(), now.hour(), now.minute(), now.second());
|
||||
display.setCursor(0,24);
|
||||
display.println(dateString);
|
||||
if (menu == 9 ){
|
||||
display.setCursor(0,0);
|
||||
display.print("MENU2");
|
||||
|
||||
|
||||
display.display();
|
||||
|
||||
yield();
|
||||
|
||||
|
||||
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 (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;
|
||||
}
|
||||
|
||||
|
||||
yield();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user