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 = 7; // 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
- unsigned long lastOn;
- // Start time
- int hodinyOn=22;
- int minutyOn=0;
- // Stop time
- int hodinyOff=6;
- int minutyOff=0;
- // 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, 10, 16, 58, 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;
- // Prevedeme casy na minuty
- int startTime = hodinyOn*60+minutyOn;
- int stopTime = hodinyOff*60+minutyOff;
- int casTed = hodinyTed*60+minutyTed;
- // 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))
- {
- if (pirState==LOW)
- {
- val = digitalRead(inputPin); // read input value
- if (val==HIGH)
- {
- lastOn=millis();
- pirState=HIGH;
- }
- }
- if (pirState == HIGH) // check if the input is HIGH
- {
- digitalWrite(ledPin, HIGH); // turn LED ON
- }
- else
- {
- digitalWrite(ledPin, LOW); // turn LED OFF
- }
- if (millis() > (lastOn + (2*60*1000))) pirState=LOW; // 2*60*1000 = 2 minuty
- }
- delay(100);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement