#include "DHT.h"
#include <Bounce2.h>
#include <Wire.h>
#include <SPI.h> // not used here, but needed to prevent a RTClib compile error
#include "RTClib.h"
/*
#define DHT1_PIN 16
#define DHT2_PIN 17
#define LED1_PIN 14 //A0
#define LED2_PIN 15 //A1
#define BOUNCE1_PIN 2
#define BOUNCE2_PIN 3
#define BOUNCE3_PIN 4
#define BUZZER_PIN 5
//-- DHT22
DHT dht1(DHT1_PIN, DHT22);
DHT dht2(DHT2_PIN, DHT22);
float humidity1, humidity2;
float tempC1, tempC2;
//-- Bounce and LED
Bounce bounce1 = Bounce();
Bounce bounce2 = Bounce();
Bounce bounce3 = Bounce();
int led1_state = LOW;
int led2_state = LOW;
bool last_button1_state = false;
bool last_button2_state = false;
bool last_button3_state = false;
*/
//-- RTC
RTC_DS1307 RTC;
//-- Counter
int i = 0;
void setup() {
Serial.begin(9600);
/*
//-- DHT
dht1.begin();
dht2.begin();
//-- Bounce
bounce1.attach( BOUNCE1_PIN , INPUT_PULLUP );
bounce2.attach( BOUNCE2_PIN , INPUT_PULLUP );
bounce3.attach( BOUNCE3_PIN , INPUT_PULLUP );
bounce1.interval(30); // interval in ms
bounce2.interval(30); // interval in ms
bounce3.interval(30); // interval in ms
pinMode(LED1_PIN, OUTPUT);
pinMode(LED2_PIN, OUTPUT);
digitalWrite(LED1_PIN, HIGH);
digitalWrite(LED2_PIN, HIGH);
pinMode(BUZZER_PIN, OUTPUT);
*/
//-- RTC
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
//RTC.adjust(DateTime(__DATE__, __TIME__)); //สำหรับตั้งเวลา เมื่อตั้งเลาแล้วให้คอมเม้น หรือลบออก
}
}
void loop() {
delay(1000);
/*
//-- Bounce
bounce1.update();
bounce2.update();
bounce3.update();
//-- Pressed button bounce = LOW, Release bounce = HIGH
if ( bounce1.changed() ) {
int deboucedInput1 = bounce1.read();
if ( deboucedInput1 == LOW ) {
Serial.println("Bounce1 triggerded LOW ");
led1_state = !led1_state;
digitalWrite(LED1_PIN,led1_state);
}
}
if ( bounce2.changed() ) {
int deboucedInput2 = bounce2.read();
if ( deboucedInput2 == LOW ) {
Serial.println("Bounce2 triggerded LOW");
led2_state = !led2_state;
digitalWrite(LED2_PIN,led2_state);
}
}
if ( bounce3.changed() ) {
int deboucedInput3 = bounce3.read();
if ( deboucedInput3 == LOW ) {
Serial.println("Bounce3 triggerded LOW");
}
}
*/
//-- RTC
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();
/*
//-- DHT
humidity1 = dht1.readHumidity();
humidity2 = dht2.readHumidity();
tempC1 = dht1.readTemperature();
tempC2 = dht2.readTemperature();
if (isnan(humidity1) || isnan(tempC1)) {
Serial.println("Failed to read from DHT1 sensor!");
}
else {
Serial.print("DHT1# Humidity: ");
Serial.print(humidity1);
Serial.print("% | Temperature1: ");
Serial.print(tempC1);
Serial.print("°C");
Serial.print("\n");
}
if (isnan(humidity2) || isnan(tempC2)) {
Serial.println("Failed to read from DHT2 sensor!");
}
else {
Serial.print("DHT2# Humidity: ");
Serial.print(humidity1);
Serial.print("% | Temperature2: ");
Serial.print(tempC1);
Serial.print("°C");
Serial.print("\n");
}
*/
}
Setting
Cancel
+
-
Sensor1
Sensor2
Work
Sensor1
Sensor2
Alarm
Lamp1
Motor
Motor
Splay1
Display1
Display2