Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <DS1302.h>
- // Create a DS1302 object.
- const int kCePin = 3; // Chip Enable
- const int kIoPin = 4; // Input/Output
- const int kSclkPin = 5; // Serial Clock
- DS1302 rtc(kCePin, kIoPin, kSclkPin);
- int ledPin = 13; // choose the pin for the LED
- int inputPin = 2; // choose the input pin (for PIR sensor)
- int pirState = LOW; // we start, assuming no motion detected
- int val = 0; // variable for reading the pin status
- // Start time
- int hodinyOn=20;
- int minutyOn=30;
- // Stop time
- int hodinyOff=22;
- int minutyOff=30;
- // Prikladne cas ted - skutecny se vezme z RTC
- int hodinyTed=20;
- int minutyTed=32;
- void setup() {
- Serial.begin(9600);
- pinMode(ledPin, OUTPUT); // declare LED as output
- pinMode(inputPin, INPUT); // declare sensor as input
- // Initialize a new chip by turning off write protection and clearing the
- // clock halt flag. These methods needn't always be called. See the DS1302
- // datasheet for details.
- rtc.writeProtect(false);
- rtc.halt(false);
- // Make a new time object to set the date and time.
- // Sunday, September 22, 2013 at 01:38:50.
- // Time t(2021, 2, 8, 18, 55, 00, Time::kMonday);
- // Set the time and date on the chip.
- // rtc.time(t);
- }
- void loop()
- {
- Time t = rtc.time();
- hodinyTed = t.hr;
- minutyTed = t.min;
- Serial.println("##############");
- Serial.print("Start ");
- Serial.print(hodinyOn);
- Serial.println(minutyOn);
- Serial.print("Stop ");
- Serial.print(hodinyOff);
- Serial.println(minutyOff);
- Serial.print("Now ");
- Serial.print(hodinyTed);
- Serial.println(minutyTed);
- Serial.println("-----------");
- // Prevedeme casy na minuty
- int startTime = hodinyOn*60+minutyOn;
- int stopTime = hodinyOff*60+minutyOff;
- int casTed = hodinyTed*60+minutyTed;
- // Vypis casu prevedenych na minuty
- Serial.print("Start");
- Serial.println(startTime);
- Serial.print("Stop");
- Serial.println(stopTime);
- Serial.print("Now");
- Serial.println(casTed);
- Serial.println("---------------");
- // Vyhodnocujeme, prvni tretina plati pro casy co nejsou pres pulnoc, dalsi 2/3 jsou pro casy co jdou pres pulnoc
- if ((startTime < stopTime && casTed > startTime && casTed < stopTime) || (startTime > stopTime && casTed > startTime) || (startTime > stopTime && casTed < stopTime)){
- Serial.println("Svitime");
- val = digitalRead(inputPin); // read input value
- if (val == HIGH) // check if the input is HIGH
- {
- digitalWrite(ledPin, HIGH); // turn LED ON
- if (pirState == LOW)
- {
- Serial.println("Motion detected!"); // print on output change
- pirState = HIGH;
- }
- }
- else
- {
- digitalWrite(ledPin, LOW); // turn LED OFF
- if (pirState == HIGH)
- {
- Serial.println("Motion ended!"); // print on output change
- pirState = LOW;
- }
- }
- }
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement