Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <DS1302.h>
- namespace {
- // Set the appropriate digital I/O pin connections. These are the pin
- // assignments for the Arduino as well for as the DS1302 chip. See the DS1302
- // datasheet:
- //
- // http://datasheets.maximintegrated.com/en/ds/DS1302.pdf
- //DS1302 pins
- const int kCePin = 10; // Chip Enable (RST)
- const int kIoPin = 9; // Input/Output (DA)
- const int kSclkPin = 8; // Serial Clock (CLK)
- //LCD pins
- //RST - 6
- //CE - 7
- //DC - 5
- //Din - 4
- //Clk - 3
- // Create a DS1302 object.
- DS1302 rtc(kCePin, kIoPin, kSclkPin);
- String dayAsString(const Time::Day day) {
- switch (day) {
- case Time::kSunday: return "Вс";
- case Time::kMonday: return "Пн";
- case Time::kTuesday: return "Вт";
- case Time::kWednesday: return "Ср";
- case Time::kThursday: return "Чт";
- case Time::kFriday: return "Пт";
- case Time::kSaturday: return "Сб";
- }
- return "(unknown day)";
- }
- } // namespace
- #include <PCD8544.h>
- static PCD8544 lcd;
- #include "DHT.h"
- #define DHTPIN 13
- #define DHTTYPE DHT11
- DHT dht(DHTPIN, DHTTYPE);
- float tempOut;
- int tOut;
- int tempOutPin = 7; // пин подключения LM35DZ
- void setup() {
- Serial.begin(9600);
- dht.begin();
- lcd.begin(84, 48);
- //раскомментить, чтобы задать время!
- // rtc.writeProtect(false);
- // rtc.halt(false);
- // Sunday, September 22, 2013 at 01:38:50.
- // Time t(2015, 3, 18, 20, 54, 50, Time::kWednesday);
- // Set the time and date on the chip.
- // rtc.time(t);
- lcd.setCursor(0,0);
- lcd.print("Подождите,");
- lcd.setCursor(0,1);
- lcd.print("включаюсь!");
- }
- void loop() {
- // Get the current time and date from the chip.
- Time t = rtc.time();
- // Name the day of the week.
- const String day = dayAsString(t.day);
- // Format the time and date and insert into the temporary buffer.
- char buf[50];
- snprintf(buf, sizeof(buf), "%s %02d.%02d.%04d %02d:%02d:%02d ",
- day.c_str(),
- t.date, t.mon, t.yr,
- t.hr, t.min, t.sec);
- if (fmod(t.min,10) == 0 && t.sec == 0) {
- lcd.clear();
- }
- if (fmod(t.sec,10) == 0) {
- int h = dht.readHumidity();
- int t = dht.readTemperature();
- tempOut = analogRead(tempOutPin);
- tempOut = tempOut * 0.48828125;
- tOut = (int) tempOut;
- if (isnan(t) || isnan(h)) {
- Serial.println("Failed to read from DHT");
- lcd.setCursor(0, 0);
- lcd.print("Failed to read from DHT");
- } else {
- lcd.setCursor(0, 0);
- lcd.print("Темп-ра Дом/Ул");
- lcd.setCursor(0, 1);
- if (t < 10) {
- lcd.print(t);
- lcd.print(" ");
- } else {
- lcd.print(t);
- }
- lcd.setCursor(12, 1);
- lcd.print(" / ");
- if (tempOut < 10) {
- lcd.print(tOut);
- lcd.print(" ");
- } else {
- lcd.print(tOut);
- }
- lcd.print(" *C");
- lcd.setCursor(0, 2);
- lcd.print("Влажность ");
- lcd.setCursor(0, 3);
- lcd.print(h);
- lcd.setCursor(12, 3);
- lcd.print("%");
- lcd.setCursor(24, 3);
- if (h < 40) {
- lcd.print("- сухо\t");
- } else if (h > 60) {
- lcd.print("- мокро\t");
- } else {
- lcd.print("- норма\t");
- }
- /* Serial.print("Humidity: ");
- Serial.print(h);
- Serial.print(" %\t");
- Serial.print("Temperature: ");
- Serial.print(t);
- Serial.println(" *C");
- Serial.print("TEMPRATURE = ");
- Serial.print(tempOut);
- Serial.print("*C");
- Serial.println();
- */
- }
- }
- // Print the formatted string to serial so we can see the time.
- Serial.println(buf);
- lcd.setCursor(0, 4);
- lcd.print(buf);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement