Kód: Vybrat vše
#include <interval.h>
#include <RTClib.h>
#include <Wire.h>
#define DELAY 50 // nastaveni rychlosti dychani
#define DELAY_MEZI 800 // prodleva mezi nadechem a vydechem
#define DELAY_PRINT 1000
#define MIN_PWM 1 // minimalni jas LED, nejmene 0
#define MAX_PWM 40 // maximalni jas LED, nejvyse 255
#define VYPNI_PWM 0
#define LED_PIN 11
bool NadechTrue = false;// priznak nadech nebo vydech
bool Dychej = false;
bool Zrovna_Dycham = false;
int PWM_VALUE = MIN_PWM;
Interval DelayInterval;
Interval DelayPrint;
RTC_DS1307 rtc;
DateTime now;
void setup() {
Serial.begin(9600);
Wire.begin();
rtc.begin();
if (!rtc.isrunning())Serial.println("RTC is NOT running!");
}
void loop() {
if (DelayPrint.expired()) {
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.print(")");
Serial.println();
DelayPrint.set(DELAY_PRINT);
}
if (now.hour() == 18 && now.minute() == 0)Dychej = true;
if (now.hour() == 18 && now.minute() == 5) Dychej = false;
if (DelayInterval.expired() && (Dychej || Zrovna_Dycham)) {
Zrovna_Dycham = true;
if (NadechTrue) {
DelayInterval.set(DELAY);
analogWrite(LED_PIN, PWM_VALUE);
PWM_VALUE++;
if (PWM_VALUE > MAX_PWM) {
DelayInterval.set(DELAY_MEZI);
PWM_VALUE = MAX_PWM;
NadechTrue = false;
}
} else {
DelayInterval.set(DELAY);
analogWrite(LED_PIN, PWM_VALUE);
PWM_VALUE--;
if (PWM_VALUE < MIN_PWM) {
DelayInterval.set(DELAY_MEZI);
PWM_VALUE = MIN_PWM;
NadechTrue = true;
Zrovna_Dycham = false;
if (!Dychej)analogWrite(LED_PIN, VYPNI_PWM);
}
}
}
}