chinese直男口爆体育生外卖, 99久久er热在这里只有精品99, 又色又爽又黄18禁美女裸身无遮挡, gogogo高清免费观看日本电视,私密按摩师高清版在线,人妻视频毛茸茸,91论坛 兴趣闲谈,欧美 亚洲 精品 8区,国产精品久久久久精品免费

電子發(fā)燒友App

硬聲App

掃碼添加小助手

加入工程師交流群

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示
創(chuàng)作
電子發(fā)燒友網(wǎng)>電子資料下載>電子資料>如何將RTC DS1與Arduino結(jié)合使用來進(jìn)行提醒

如何將RTC DS1與Arduino結(jié)合使用來進(jìn)行提醒

2023-01-03 | zip | 0.01 MB | 次下載 | 免費

資料介紹

描述

概述

在許多電子項目中,需要根據(jù)時間或日期運行一個操作,并且時間和日期的計算不應(yīng)該在系統(tǒng)關(guān)閉時停止。為此,使用了實時時鐘 (RTC) 模塊。在本教程中,您將學(xué)習(xí)如何將 RTC DS1 與 Arduino 結(jié)合使用來進(jìn)行提醒。

你將學(xué)到什么:

  • 什么是實時時鐘
  • DS1307模塊介紹
  • 如何在 Arduino 上使用 DS1307
  • 如何做一個智能提醒

?

?
poYBAGOrtkuAH6NgAACsKvtN9n8397.jpg
?

什么是實時時鐘?

實時時鐘或 RTC 是一種跟蹤當(dāng)前時間的系統(tǒng),可用于任何需要保持準(zhǔn)確時間的設(shè)備。

?

?
pYYBAGOrtk6AadniAAAzIYaIJMA516.jpg
?

您也可以在不使用 RTC 系統(tǒng)的情況下跟蹤準(zhǔn)確時間,但 RTC 具有一些重要的優(yōu)勢。以下是其中一些優(yōu)點:

  • 低功耗
  • 從時間計算中釋放系統(tǒng)時間(此功能很關(guān)鍵,因為在許多情況下 CPU 正在執(zhí)行一些微妙的任務(wù),例如接收傳感器數(shù)據(jù)。如果您不使用 RTC,CPU 還必須跟蹤時間,這可能會破壞處理器主任務(wù)。)
  • 高準(zhǔn)確率

RTC 通常有備用電源,因此它們可以在主電源關(guān)閉或不可用時繼續(xù)計時。RTC 通常使用 32.768 kHz 晶體振蕩器。但為什么是 32、768?32768 等于 215,因此可以輕松生成 1 秒。另外,晶體必須小,寬度適當(dāng),功耗低,使用32876 Hz即可滿足。較高的頻率是較大且易碎的晶體,而較低的頻率比 32、768KHz 具有更多的功耗。

您也可以在不使用 RTC 系統(tǒng)的情況下跟蹤準(zhǔn)確時間,但 RTC 具有一些重要的優(yōu)勢。以下是其中一些優(yōu)點:

  • 低功耗
  • 從時間計算中釋放系統(tǒng)時間(此功能很關(guān)鍵,因為在許多情況下 CPU 正在執(zhí)行一些微妙的任務(wù),例如接收傳感器數(shù)據(jù)。如果您不使用 RTC,CPU 還必須跟蹤時間,這可能會破壞處理器主任務(wù)。)
  • 高準(zhǔn)確率

RTC 通常有備用電源,因此它們可以在主電源關(guān)閉或不可用時繼續(xù)計時。RTC 通常使用 32.768 kHz 晶體振蕩器。但為什么是 32、768?32768 等于 215,因此可以輕松生成 1 秒。另外,晶體必須小,寬度適當(dāng),功耗低,使用32876 Hz即可滿足。較高的頻率是較大且易碎的晶體,而較低的頻率比 32、768KHz 具有更多的功耗。

DS1307 模塊特性和規(guī)格

DS1307 模塊是最實惠和最常見的 RTC 模塊之一。它可以準(zhǔn)確地記錄秒、分、時、日、月和年。

DS1307 的一些重要特性是:

  • 產(chǎn)生可編程方波的能力
  • 電流使用;在電池備份模式下低于 500nA
  • 將日期設(shè)置為 2100 年的能力
  • I2C 串行接口

DS1307 模塊能夠安裝 3 伏 CR2023 備用電池。該模塊上還有一個嵌入式 EEPROM 24c32 存儲器,可以保存 32kb 的數(shù)據(jù)。此外,您還可以通過在內(nèi)置位置安裝一個DS18B20傳感器來測量環(huán)境溫度。您還可以從 BAT 引腳讀取備用電池電壓。

?

?
poYBAGOrtlCAQTYzAAA47qk4vQc935.jpg
?

?

?
pYYBAGOrtlKAVyuNAABt34nPbaM331.png
?

將 DS1307 與 Arduino 連接

該模塊使用簡單,RTC部分使用I2C協(xié)議與微控制器通信

電路

?

?
pYYBAGOuPMSAVLHrAACvrZuQxhI561.jpg
?

代碼

您需要 RTClib 庫才能將 DS1307 與 Arduino 一起使用。

現(xiàn)在將以下代碼上傳到您的板上,并在串行監(jiān)視器窗口中查看結(jié)果。

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include 
#include "RTClib.h"
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void setup () {
 while (!Serial); // for Leonardo/Micro/Zero
 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();
 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 and 30 seconds into the future
 DateTime future (now + TimeSpan(7, 12, 30, 6));
 Serial.print(" now + 7d + 30s: ");
 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.println();
 delay(3000);
}

您可以通過兩種方式設(shè)置日期和時間。首先是使用以下代碼在您的 PC 上設(shè)置它們:

rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); 

第二種方法是使用以下代碼手動設(shè)置日期和時間:

rtc.adjust(DateTime(YEAR, MONTH, DAY, HOUR , MINUTE, SECOND));

注意您只需在項目中設(shè)置一次日期和時間,之后,您應(yīng)該從代碼中刪除相關(guān)行。否則,每次打開系統(tǒng)時都會設(shè)置日期和時間,這可能會導(dǎo)致一些錯誤。

注意在您的 Arduino 上上傳代碼需要幾秒鐘,與實時相比,這可能會導(dǎo)致您的時間延遲幾秒鐘。所以我們建議您在上傳代碼之前將您的時間提前幾秒。

獎勵項目:做一個智能提醒

您可以使用 DS1307 模塊制作一個簡單而有用的提醒。

其他所需材料

LCD 鍵盤護(hù)罩

無源蜂鳴器

電路

?

?
pYYBAGOuPMaAReCAAADlRc4GyYs917.jpg
?

?

代碼

將以下代碼上傳到您的 Arduino 板上,您的智能提醒已準(zhǔn)備就緒!

/*
Arduino Reminder
modified on 13 March 2019
by Saeed Hosseini @ Electropeak
https://electropeak.com/learn/
*/
#include #include #include "RTClib.h"
#define NOTE_C4  262
#define NOTE_D4  294
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_G4  392
#define NOTE_A4  440
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_D5  587
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_G5  784
#define NOTE_A5  880
#define NOTE_B5  988
//LCD Pin to Arduino
const int pin_RS = 8;
const int pin_EN = 9;
const int pin_d4 = 4;
const int pin_d5 = 5;
const int pin_d6 = 6;
const int pin_d7 = 7;
const int pin_BL = 10;
//BUZZER Pin to Arduino
const int buzzer = 2;  
LiquidCrystal lcd( pin_RS,  pin_EN,  pin_d4,  pin_d5,  pin_d6,  pin_d7);
RTC_DS1307 rtc;
byte smiley[8] = {
 B00000,
 B10001,
 B00000,
 B00000,
 B10001,
 B01110,
 B00000,
};
String menuItems[] = {"1-Medicin", "2-Wake up", "3-Go out"};
int songspeed = 1.5;
int flag = 0;
int menuPage = 0;
int maxMenuPages = round(((sizeof(menuItems) / sizeof(String)) / 2) + .5);
int cursorPosition = 0;
int btn;
int h = 0, m = 0;
int duration[] = {         //duration of each note (in ms) Quarter Note is set to 250 ms
 125, 125, 250, 125, 125,
 125, 125, 250, 125, 125,
 125, 125, 250, 125, 125,
 125, 125, 375, 125,
 125, 125, 250, 125, 125,
 125, 125, 250, 125, 125,
 125, 125, 250, 125, 125,
 125, 125, 375, 125,
 125, 125, 250, 125, 125,
 125, 125, 250, 125, 125,
 125, 125, 250, 125, 125,
 125, 125, 125, 250, 125,
 125, 125, 250, 125, 125,
 250, 125, 250, 125,
 125, 125, 250, 125, 125,
 125, 125, 375, 375,
 250, 125,
 //Rpeat of First Part
 125, 125, 250, 125, 125,
 125, 125, 250, 125, 125,
 125, 125, 375, 125,
 125, 125, 250, 125, 125,
 125, 125, 250, 125, 125,
 125, 125, 250, 125, 125,
 125, 125, 375, 125,
 125, 125, 250, 125, 125,
 125, 125, 250, 125, 125,
 125, 125, 250, 125, 125,
 125, 125, 125, 250, 125,
 125, 125, 250, 125, 125,
 250, 125, 250, 125,
 125, 125, 250, 125, 125,
 125, 125, 375, 375,
 //End of Repeat
 250, 125, 375, 250, 125, 375,
 125, 125, 125, 125, 125, 125, 125, 125, 375,
 250, 125, 375, 250, 125, 375,
 125, 125, 125, 125, 125, 500,
 250, 125, 375, 250, 125, 375,
 125, 125, 125, 125, 125, 125, 125, 125, 375,
 250, 125, 375, 250, 125, 375,
 125, 125, 125, 125, 125, 500
};
int notes[] = {       //Note of the song, 0 is a rest/pulse
 NOTE_E4, NOTE_G4,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 0,
 NOTE_A4, NOTE_C5, NOTE_B4, NOTE_B4, 0,
 NOTE_C5, NOTE_A4, NOTE_B4, 0,
 //End of Repeat
 NOTE_E5, 0, 0, NOTE_F5, 0, 0,
 NOTE_E5, NOTE_E5, 0, NOTE_G5, 0, NOTE_E5, NOTE_D5, 0, 0,
 NOTE_D5, 0, 0, NOTE_C5, 0, 0,
 NOTE_B4, NOTE_C5, 0, NOTE_B4, 0, NOTE_A4,
 NOTE_E5, 0, 0, NOTE_F5, 0, 0,
 NOTE_E5, NOTE_E5, 0, NOTE_G5, 0, NOTE_E5, NOTE_D5, 0, 0,
 NOTE_D5, 0, 0, NOTE_C5, 0, 0,
 NOTE_B4, NOTE_C5, 0, NOTE_B4, 0, NOTE_A4
};
void show_time()
{
 lcd.clear();
 DateTime now = rtc.now();
 lcd.setCursor(0, 0);
 lcd.print("* Electropeak *");
 lcd.setCursor(5, 0);
 lcd.print(now.hour(), DEC);
 lcd.print(":");
 lcd.print(now.minute(), DEC);
 if (now.hour() == h && now.minute() == m)
 {
   lcd.clear();
   lcd.setCursor(0 , 0);
   switch (flag)
   {
     case 1:
       lcd.print("** ?edicine Time **");
       break;
     case 2:
       lcd.print("You'r late!!");
       lcd.setCursor(0, 1);
       lcd.print("Come onnnnnnn");
       break;
     case 3:
       lcd.print("Befor you go:");
       lcd.setCursor(0, 1);
       lcd.print("Wallet,Keys,...");
       break;
   }
   for (int i = 0; i < 203; i++) {       //203 is the total number of music notes in the song
     int wait = duration[i] * songspeed;
     tone(buzzer, notes[i], wait);        //tone(pin,frequency,duration)
     delay(wait);
   }
 }
 delay(2000);
}
void welcome_menu(int show_delay)
{
 lcd.setCursor(0, 0);
 lcd.print("Arduino reminder");
 lcd.createChar(1, smiley);
 lcd.setCursor(7, 1);
 lcd.write(1);
 delay(show_delay);
 lcd.clear();
}
int detect_button() {
 int readkey = 0;
 int result = 0;
 int activeButton = 0;
 while (activeButton == 0) {
   readkey = analogRead(0);
   if (readkey < 790) {
     delay(100);
     readkey = analogRead(0);
     if (readkey < 60) {
       result = 1; // right
     } else if (readkey < 200) {
       result = 2; // up
     } else if (readkey < 400) {
       result = 3; // down
     } else if (readkey < 600) {
       result = 4; // down
     } else if (readkey < 800) { result = 5; // select } return result; } } activeButton = 1; } int choose_menu() { lcd.clear(); lcd.print("Remmeber what?"); while (btn != 5) { btn = detect_button(); if (btn == 1) { if (menuPage > maxMenuPages) menuPage = 0;
     lcd.clear();
     lcd.print("Remmeber what?");
     lcd.setCursor(0, 1);
     lcd.print(menuItems[menuPage]);
     menuPage = menuPage + 1;
   }
 }
 return menuPage;
}
void set_alarm() {
 int sit = 0;
 lcd.clear();
 lcd.setCursor(1, 0);
 lcd.print("**Set Alarm**");
 lcd.setCursor(5, 1);
 lcd.print("00:00");
 while (sit != 1)
 {
   sit = detect_button();
   if (sit == 2)
   {
     lcd.clear();
     lcd.setCursor(1, 0);
     lcd.print("**Set Alarm**");
     h++;
     if (h > 23)
     {
       h = 0;
     }
     lcd.setCursor(5, 1);
     lcd.print(h);
     lcd.print(":00");
   }
   else if (sit == 3)
   {
     lcd.clear();
     lcd.setCursor(1, 0);
     lcd.print("**Set Alarm**");
     h--;
     if (h < 0) { h = 23; } lcd.setCursor(5, 1); lcd.print(h); lcd.print(":00"); } } while (sit != 5) { sit = detect_button(); if (sit == 2) { lcd.clear(); lcd.setCursor(1, 0); lcd.print("**Set Alarm**"); m++; if (m > 59)
     {
       m = 0;
     }
     lcd.setCursor(5, 1);
     lcd.print(h);
     lcd.print(":");
     lcd.print(m);
   }
   else if (sit == 3)
   {
     lcd.clear();
     lcd.setCursor(1, 0);
     lcd.print("**Set Alarm**");
     m--;
     if (m < 0)
     {
       m = 59;
     }
     lcd.setCursor(5, 1);
     lcd.print(h);
     lcd.print(":");
     lcd.print(m);
   }
 }
 lcd.clear();
 lcd.setCursor(0, 0);
 lcd.print("Alarm set");
 lcd.setCursor(0, 1);
 lcd.print("I'll be on time");
 delay(1500);
}
void setup() {
 lcd.begin(16, 2);
 rtc.begin();
 pinMode(buzzer, OUTPUT);
 welcome_menu(1000);
 flag = choose_menu();
 set_alarm();
}
void loop()
{
 show_time();
} 

?

如果您需要有關(guān) LCD Keypad Shield 的更多信息,請閱讀Using 1602 LCD Keypad Shield w/ Arduino [+Practical Projects]。

打開設(shè)備后,LCD 上會顯示一個菜單。選擇您的提醒模式(您可以通過右鍵在選項之間移動并通過按選擇鍵選擇您想要的模式。)然后設(shè)置您的鬧鐘時間(通過向上和向下鍵設(shè)置小時,然后通過向右轉(zhuǎn)到分鐘并設(shè)置它.) 現(xiàn)在開始您的日常工作,不用擔(dān)心!

下一步是什么?

  • 試著做一個叫醒鬧鐘
  • 在 DS1307 模塊上安裝溫度傳感器,嘗試用 TFT LCD 制作一個顯示環(huán)境溫度的酷炫圖形時鐘 2, 4

RTC Arduino DS1307
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

下載該資料的人也在下載 下載該資料的人還在閱讀
更多 >

評論

查看更多

下載排行

本周

  1. 1山景DSP芯片AP8248A2數(shù)據(jù)手冊
  2. 1.06 MB  |  532次下載  |  免費
  3. 2RK3399完整板原理圖(支持平板,盒子VR)
  4. 3.28 MB  |  339次下載  |  免費
  5. 3TC358743XBG評估板參考手冊
  6. 1.36 MB  |  330次下載  |  免費
  7. 4DFM軟件使用教程
  8. 0.84 MB  |  295次下載  |  免費
  9. 5元宇宙深度解析—未來的未來-風(fēng)口還是泡沫
  10. 6.40 MB  |  227次下載  |  免費
  11. 6迪文DGUS開發(fā)指南
  12. 31.67 MB  |  194次下載  |  免費
  13. 7元宇宙底層硬件系列報告
  14. 13.42 MB  |  182次下載  |  免費
  15. 8FP5207XR-G1中文應(yīng)用手冊
  16. 1.09 MB  |  178次下載  |  免費

本月

  1. 1OrCAD10.5下載OrCAD10.5中文版軟件
  2. 0.00 MB  |  234315次下載  |  免費
  3. 2555集成電路應(yīng)用800例(新編版)
  4. 0.00 MB  |  33566次下載  |  免費
  5. 3接口電路圖大全
  6. 未知  |  30323次下載  |  免費
  7. 4開關(guān)電源設(shè)計實例指南
  8. 未知  |  21549次下載  |  免費
  9. 5電氣工程師手冊免費下載(新編第二版pdf電子書)
  10. 0.00 MB  |  15349次下載  |  免費
  11. 6數(shù)字電路基礎(chǔ)pdf(下載)
  12. 未知  |  13750次下載  |  免費
  13. 7電子制作實例集錦 下載
  14. 未知  |  8113次下載  |  免費
  15. 8《LED驅(qū)動電路設(shè)計》 溫德爾著
  16. 0.00 MB  |  6656次下載  |  免費

總榜

  1. 1matlab軟件下載入口
  2. 未知  |  935054次下載  |  免費
  3. 2protel99se軟件下載(可英文版轉(zhuǎn)中文版)
  4. 78.1 MB  |  537798次下載  |  免費
  5. 3MATLAB 7.1 下載 (含軟件介紹)
  6. 未知  |  420027次下載  |  免費
  7. 4OrCAD10.5下載OrCAD10.5中文版軟件
  8. 0.00 MB  |  234315次下載  |  免費
  9. 5Altium DXP2002下載入口
  10. 未知  |  233046次下載  |  免費
  11. 6電路仿真軟件multisim 10.0免費下載
  12. 340992  |  191187次下載  |  免費
  13. 7十天學(xué)會AVR單片機(jī)與C語言視頻教程 下載
  14. 158M  |  183279次下載  |  免費
  15. 8proe5.0野火版下載(中文版免費下載)
  16. 未知  |  138040次下載  |  免費