Μετάβαση στο κύριο περιεχόμενο

RTC Clock ΟΜΙΛΟΣ ARDUINO

 RTC Clock


 


Κώδικας για εκκίνηση του RTC με τη χρήση της ώρας του υπολογιστή 

 // Date and time functions using a DS3231 RTC connected via I2C and Wire lib
// Reads time and date from pc and initializes rtc clock
#include "RTClib.h"

RTC_DS3231 rtc;

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

void setup () {
  Serial.begin(57600);

#ifndef ESP8266
  while (!Serial); // wait for serial port to connect. Needed for native USB
#endif

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

  if (rtc.lostPower()) {
    Serial.println("RTC lost power, let's set the time!");
    // When time needs to be set on a new device, or after a power loss, the
    // 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));
  }

  // When time needs to be re-set on a previously configured device, the
  // 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();

    Serial.print(" since midnight 1/1/1970 = ");
    Serial.print(now.unixtime());
    Serial.print("s = ");
    Serial.print(now.unixtime() / 86400L);
    Serial.println("d");

    // calculate a date which is 7 days, 12 hours, 30 minutes, 6 seconds into the future
    DateTime future (now + TimeSpan(7,12,30,6));

    Serial.print(" now + 7d + 12h + 30m + 6s: ");
    Serial.print(future.year(), DEC);
    Serial.print('/');
    Serial.print(future.month(), DEC);
    Serial.print('/');
    Serial.print(future.day(), DEC);
    Serial.print(' ');
    Serial.print(future.hour(), DEC);
    Serial.print(':');
    Serial.print(future.minute(), DEC);
    Serial.print(':');
    Serial.print(future.second(), DEC);
    Serial.println();

    Serial.print("Temperature: ");
    Serial.print(rtc.getTemperature());
    Serial.println(" C");

    Serial.println();
    delay(3000);
}

Σχόλια

Δημοφιλείς αναρτήσεις από αυτό το ιστολόγιο

Tmp36GZ θερμόμετρο με LCD οθόνη

 Tmp36GZ με LCD οθόνη // Define to which pin of the Arduino the output of the TMP36 is connected: #include <LiquidCrystal_I2C.h> // Look for LiquidCrystal I2C library by Marco Schwartz LiquidCrystal_I2C lcd ( 0x 27 , 16 , 2 ) ;  // set the LCD address to 0x3F for a 16 chars and 2 line display #define sensorPin A0 void setup () {   // Begin serial communication at a baud rate of 9600:   Serial . begin ( 9600 ) ;   lcd . init () ;   lcd . clear () ;           lcd . backlight () ;      // Make sure backlight is on     // Print a message on both lines of the LCD.   lcd . setCursor ( 2 , 0 ) ;   //Set cursor to character 2 on line 0   lcd . print ( "Hello world!" ) ;     lcd . setCursor ( 2 , 1 ) ;   //Move cursor to character 2 on line 1   lcd . print ( "LCD Tutorial" ) ; } void loop () {   // Get a reading from the temperature sensor:   int reading ...

Σερβοκινητήρας

  Βασικός έλεγχος σερβομηχανισμού Θα μάθουμε πώς να ελέγχετε έναν τυπικό σερβοκινητήρα, να πηγαίνει εμπρός και πίσω κατά 180 μοίρες, χρησιμοποιώντας ένα «βρόχο for()». Αυτό γίνεται με τη βοήθεια της βιβλιοθήκης Servo, η οποία είναι προεγκατεστημένη βιβλιοθήκη στο Arduino IDE (τόσο εκτός σύνδεσης όσο και σε ηλεκτρονική έκδοση). . Αυτό γίνεται με τη βοήθεια της βιβλιοθήκης  Servo     , η οποία είναι προεγκατεστημένη βιβλιοθήκη στο Arduino IDE (τόσο εκτός σύνδεσης όσο και σε ηλεκτρονική έκδοση).      Χρειαζόμαστε τα παρακάτω:     Arduino IDE Arduino UNO  Σερβοκινητήρας 4,8V - 6V  Καλώδια βραχυκυκλωτήρα. Τυπικοί σερβοκινητήρες Οι τυπικοί σερβοκινητήρες είναι ενεργοποιητές που επιτρέπουν τον ακριβή έλεγχο της θέσης (γωνία). Χαρακτηριστικό  είναι ότι η γωνία του κινητήρα είναι 0 - 180 μοίρες. Με άλλα λόγια, μπορεί να κάνει το μισό μιας περιστροφής. Ένας τυπικός σερβοκινητήρας, όπως και άλλοι κινητήρες, είναι ουσιαστικά απλώς ένας...

Αντιστάσεις pull up, pull down

  Αντιστάσεις pull up (Pull up resistors) Οι αντιστάσεις pull up  είναι πολύ συνηθισμένες όταν χρησιμοποιούνται μικροελεγκτές (MCU) ή οποιαδήποτε συσκευή ψηφιακής λογικής. Θα εξηγήσουμε πότε και πού να χρησιμοποιήσετε αντιστάσεις pull up και, στη συνέχεια, θα κάνουμε έναν απλό υπολογισμό για να δείξουμε γιατί είναι σημαντικά τα pull-ups. Τι είναι μια αντίσταση  Pull up Ας υποθέσουμε ότι έχετε ένα MCU με ένα pin διαμορφωμένο ως είσοδο. Εάν δεν υπάρχει τίποτα συνδεδεμένο με τον ακροδέκτη και το πρόγραμμά σας διαβάζει την κατάσταση του ακροδέκτη, θα είναι ψηλά (τραβηγμένο στο VCC) ή χαμηλό (τραβηγμένο στη γείωση);  Αυτό το φαινόμενο αναφέρεται ως  αιωρούμενο  (floating). Για να αποφευχθεί αυτή η άγνωστη κατάσταση, μια αντίσταση pull-up ή pull-down θα διασφαλίσει ότι η ακίδα βρίσκεται είτε σε υψηλή είτε σε χαμηλή κατάσταση, ενώ χρησιμοποιεί επίσης χαμηλή ποσότητα ρεύματος. Για απλότητα, θα εστιάσουμε στα pull-ups καθώς είναι πιο συνηθισμένα από τα pull-down. Λε...