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

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);
}

Σχόλια

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

PWM στο Arduino

  PWM στο Arduino Εισαγωγή στο PWM Η διαμόρφωση πλάτους παλμού (PWM)   είναι μια τεχνική με την οποία το πλάτος ενός παλμού μεταβάλλεται διατηρώντας τη συχνότητα του κύματος σταθερή. Είναι μια μέθοδος παραγωγής αναλογικού σήματος με χρήση ψηφιακής πηγής. Γενιά PWM   Ένα σήμα PWM αποτελείται από δύο κύρια στοιχεία που καθορίζουν τη συμπεριφορά του: έναν  κύκλο λειτουργίας  και μια  συχνότητα  .   Τι είναι ο κύκλος λειτουργίας του σήματος Η περίοδος ενός παλμού αποτελείται από έναν  κύκλο  ON   (5V) και έναν    κύκλο  OFF  (0V). Το κλάσμα για το οποίο το σήμα είναι ενεργοποιημένο για μια περίοδο είναι γνωστό ως   κύκλος λειτουργίας  . Π.χ.  Ένας παλμός με περίοδο 10 ms θα παραμείνει ενεργός (υψηλό) για 2 ms. Επομένως, ο κύκλος λειτουργίας θα είναι D = 2ms / 10ms = 20%   Μέσω της τεχνικής PWM, μπορούμε να ελέγξουμε την ισχύ που παρέχεται στο φορτίο χρησιμοποιώντας το σήμα ON-O...

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 ...

Πώς να χρησιμοποιήσετε ένα Breadboard

  Πώς να χρησιμοποιήσετε ένα Breadboard Το breadboard έχει εσωτερικές συνδέσεις μεταξύ των οπών του. Μερικές κάθετες συνδέσεις και μερικές οριζόντιες συνδέσεις. Κανονικά, χρησιμοποιείτε τις κολώνες στα πλάγια για να συνδέσετε το τροφοδοτικό σας. Και χρησιμοποιείτε τις σειρές στη μέση για να συνδέσετε τα στοιχεία σας. Στήλες Τροφοδοτικού Είναι σύνηθες να χρησιμοποιείτε τις στήλες στα αριστερά και δεξιά για τη σύνδεση του τροφοδοτικού. Αυτές οι στήλες συνδέονται κάθετα. Έτσι, εάν συνδέσετε 5 βολτ στην επάνω οπή μιας από τις πλευρικές κολώνες, θα έχετε 5 βολτ σε όλες τις οπές αυτής της στήλης. Χρησιμοποιήστε τις στήλες που επισημαίνονται με κόκκινη γραμμή για το συν και τη στήλη με μπλε γραμμή για το μείον. Τέλος φόρμας Σημείωση: Μερικές μεγαλύτερες πλάκες   breadboard χωρίζονται στα δύο έτσι ώστε το πάνω μισό να αποσυνδεθεί από το κάτω μισό. Αυτό υποδεικνύεται από τις κατακόρυφες μπλε και κόκκινες γραμμές που χωρίζονται στα δύο.   Περιοχή Συστατικού Σ...