Hirdetés

Új hozzászólás Aktív témák

  • ngabor2

    nagyúr

    Megírtam/összeollóztam Arduino Nano-ra egy egyszerű időzítőt DS3231-gyel és egy relével a D2 pinre kötve.

    A program:
    #include <Wire.h>
    #include "RTClib.h"

    RTC_DS3231 rtc;
    int p2=0;


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

    void setup () {
    pinMode(2, OUTPUT);

    #ifndef ESP8266
    while (!Serial); // for Leonardo/Micro/Zero
    #endif

    Serial.begin(9600);

    delay(3000); // wait for console opening

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

    if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
    // 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 t = rtc.now();

    Serial.print(t.year(), DEC);
    Serial.print('/');
    Serial.print(t.month(), DEC);
    Serial.print('/');
    Serial.print(t.day(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[t.dayOfTheWeek()]);
    Serial.print(") ");
    Serial.print(t.hour(), DEC);
    Serial.print(':');
    Serial.print(t.minute(), DEC);
    Serial.print(':');
    Serial.print(t.second(), DEC);
    Serial.println();

    if (t.hour() > 5 && t.hour() < 18 ){
    digitalWrite(2, LOW);
    }
    else{
    digitalWrite(2, HIGH);
    }

    delay(3000);
    }

    Elvileg reggel 6-kor bekapcsol, este 6-kor kikapcsol... de nem kapcsol ki. Teljesen hasonlóan van egy másikra megírva, az működik (a különbség annyi, hogy ott a 4-es pinen van a relé). Hol van a hiba? Az időt szépen kiírja, tehát az órával elvileg nincs gond. Több ötletem nincs.

Új hozzászólás Aktív témák