Anonymous Anonymous - 10 months ago
576 0

No description

Other

Aquarium_LED_Dimmer

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"

int ledPin = 9;
RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Sunday", "Saturday"};

void setup () {
  Serial.begin(57600);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
}

void loop () {
  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(daysOfTheWeek[now.dayOfTheWeek()]);
  Serial.print(") ");
  Serial.print(now.hour(), DEC);
  Serial.print(':');
  Serial.print(now.minute(), DEC);
  Serial.print(':');
  Serial.print(now.second(), DEC);
  Serial.println();
  // MOON 1
  if (now.hour() == 00 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 5; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }
  // MOON 2
  if (now.hour() == 1 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 5; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }
  // MOON 3
  if (now.hour() == 2 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 5; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }
  // MOON 4
  if (now.hour() == 3 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 5; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }
  // MOON 5
  if (now.hour() == 4 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 5; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }
  // MOON 6
  if (now.hour() == 5 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 5; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }
  // MOON 7
  if (now.hour() == 6 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 5; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }
  // MOON 8
  if (now.hour() == 7 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 5; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }
  // MOON 9
  if (now.hour() == 8 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 5; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }
  // MOON 10
  if (now.hour() == 9 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 5; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }
  // MOON 11
  if (now.hour() == 10 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 5; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }
  // MOON 12
  if (now.hour() == 11 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 5; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }
  // MOON 13
  if (now.hour() == 12 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 5; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }
  // MOON 14
  if (now.hour() == 13 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 5; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }
  // MOON 15
  if (now.hour() == 14 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 5; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }
  // MOON 16
  if (now.hour() == 15 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 5; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }
  // MOON 17
  if (now.hour() == 16 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 5; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }
  // sunrise on 25%
  if (now.hour() == 16 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 127; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }
  // sunrise on 50%
  if (now.hour() == 17 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 127; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }
  // sunrise 80%
  if (now.hour() == 18 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 127; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }
  // solstice 100%
  if (now.hour() == 19 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 127; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }
  // solstice 100%
  if (now.hour() == 20 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 127; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }
  // sunset 80%
  if (now.hour() == 21 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 127; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }
  //sunset 50%
  if (now.hour() == 22 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 127; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }
  // sunset 25%
  if (now.hour() == 23 && now.minute() == 00)
  {
    for (int fadeValue = 0 ; fadeValue <= 127; fadeValue += 5)
      analogWrite(ledPin, fadeValue);
  }


  delay(3000);
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download