Mundarija:

Arduino -ni aylantiruvchi matnli soat: 3 qadam
Arduino -ni aylantiruvchi matnli soat: 3 qadam

Video: Arduino -ni aylantiruvchi matnli soat: 3 qadam

Video: Arduino -ni aylantiruvchi matnli soat: 3 qadam
Video: Chiziqli programmalashtirish masalasini simpleks usulda yechish 2024, Noyabr
Anonim
Arduino -ga aylanadigan matnli soat
Arduino -ga aylanadigan matnli soat

Loyihaning maqsadi vaqtni aytilgan vaqtini ko'rsatadigan aylanadigan matnli soatni yaratishdir (masalan, "yarim tunda").

Bu tezkor loyiha - biz sizga asbob -uskunalar va eskizlar bilan shug'ullanish uchun etarlicha ma'lumot beramiz, keyin siz uni ehtiyojlaringizga moslashtirishingiz mumkin.

1 -qadam: Uskuna

Uskuna
Uskuna

Sizga uchta asosiy element kerak bo'ladi -

  • Arduino Uno-ga mos keladigan taxta
  • DS1307 yoki DS3231 IC dan foydalanadigan real vaqtda soat sxemasi yoki moduli
  • va monoxrom P10 uslubidagi LED displey

Siz tashqi quvvat manbaiga muhtoj bo'lishingiz mumkin, lekin keyinroq bunga erishamiz.

Birinchi bosqich-bu sizning real vaqtingizga mos kelish. Agar sizga yordam kerak bo'lsa, dars uchun bu erni bosing.

Umid qilamanki, siz "vaqtni qanday belgilaysiz?" Deb o'ylaysiz.

Bu savolga ikkita javob bor. Agar siz DS3231 -dan foydalanayotgan bo'lsangiz, uni eskizga qo'ying (pastga qarang), chunki aniqlik juda yaxshi, kunduzgi vaqtni tejash uchun yiliga ikki marta eskizni yangi vaqt bilan yuklash kifoya.

Aks holda, oddiy foydalanuvchi interfeysini qo'shing-bir nechta tugmalar buni qila oladi. Nihoyat, siz uskunani DMD orqasiga qo'yishingiz kerak. O'z ehtiyojlaringizni qondirish uchun juda ko'p imkoniyatlar mavjud, siz USB -rozetkaga osongina kirishingiz uchun boshqaruv panelini tekislashingiz mumkin va keyin uni Sugru bilan yopishtiring.

Soatni quvvatlantirish borasida - siz Arduino -dan ONE LED displeyini ishga tushirishingiz mumkin va u ichki foydalanish uchun yaxshi yorqinlikda ishlaydi. Agar siz DMD to'liq ishlashini xohlasangiz, to'r pardasi yonib ketadigan yorqinligi uchun siz alohida 5V 4A doimiy quvvat manbaidan foydalanishingiz kerak. Agar siz ikkita DMDdan foydalansangiz - bu 8A ga to'g'ri keladi va hokazo. Tashqi quvvatni faqat bitta DMD terminaliga ulang (bu terminallarga ikkinchi yoki undan ko'p DMD ulang).

Agar siz elektr simining uchini kesishni xohlamasangiz, shahar rozetkasidan foydalaning.

2 -qadam: Arduino eskizi

Siz quyidagi ikkita Arduino kutubxonasini o'rnatishingiz kerak bo'ladi - TimerOne va DMD. Keyin eskizni yuklang:

// RTC #uchun "Wire.h" ni qo'shing #DS1307_I2C_ADDRESS 0x68 ni belgilang // DS1307 RTC - 0x68

// LED displey uchun

#"SPI.h" ni qo'shish #"DMD.h" ni qo'shish #"TimerOne.h" ni qo'shish #"SystemFont5x7.h" ni qo'shish #"Arial_black_16.h" ni qo'shish #DISPLAYS_ACROSS 1 ni belgilash // sizda bir nechta DMD bo'lishi mumkin qator #define DISPLAYS_DOWN 1 DMD dmd (DISPLAYS_ACROSS, DISPLAYS_DOWN);

String finalString; // DMDda ko'rsatish uchun oxirgi jumlani ushlab turish uchun ishlatilgan

void ScanDMD () // DMD uchun zarur

{dmd.scanDisplayBySPI (); }

bo'sh o'rnatish ()

{// DMD Timer1.initialize uchun (5000); Taymer1.attachInterrupt (ScanDMD); dmd.clearScreen (haqiqiy);

// RTC uchun

Wire.begin (); // I2C avtobus baytini ikkinchi, daqiqa, soat, dayOfWeek, dayOfMonth, oy, yil yoqish; // o'zgaruvchilarni o'zgartiring va vaqtni belgilash uchun setDateDs1307-ga izoh qoldirmang // keyin funktsiyani qayta sharhlang va eskizni ikkinchi soniyada yuklang = 0; daqiqa = 13; soat = 23; dayOfWeek = 4; dayOfMonth = 19; oy = 5; yil = 13; // setDateDs1307 (ikkinchi, daqiqa, soat, dayOfWeek, dayOfMonth, oy, yil); }

// odatiy RTC funktsiyalari

// Oddiy kasr sonlarini ikkilik kodli o'nli baytga aylantirish decToBcd (bayt val) {return ((val/10*16) + (val%10)); }

// Ikkilik kodli o'nli kasrni oddiy kasr sonlariga aylantirish

bayt bcdToDec (bayt val) {qaytish ((val/16*10) + (val%16)); }

void setDateDs1307 (bayt soniya, // 0-59

bayt daqiqa, // 0-59 bayt soat, // 1-23 bayt kunOfWeek, //OyMda 1-7 bayt kun, // 1-28/29/bayt oy, // 1-12 bayt yil) // 0- 99 {Wire.beginTransmission (DS1307_I2C_ADDRESS); Wire.write (0); Wire.write (decToBcd (ikkinchi)); // 0 dan 7 bitgacha Wire.write soatini ishga tushiradi (decToBcd (daqiqa)); Wire.write (decToBcd (soat)); Wire.write (decToBcd (dayOfWeek)); Wire.write (decToBcd (dayOfMonth)); Wire.write (decToBcd (oy)); Wire.write (decToBcd (yil)); Wire.write (00010000); // nazorat registriga 0x10 (oltilik) 00010000 (ikkilik) yuboradi - Wire.endTransmission kvadrat to'lqinini yoqadi; }

// ds1307 dan sana va vaqtni oladi

void getDateDs1307 (bayt *sekund, bayt *daqiqa, bayt *soat, bayt *dayOfWeek, bayt *dayOfMonth, bayt *oy, bayt *yil) {// Registratsiya ko'rsatgichini qayta o'rnatish Wire.beginTransmission (DS1307_I2C_ADDRESS); Wire.write (0); Wire.endTransmission ();

Wire.requestFrom (DS1307_I2C_ADDRESS, 7);

// Ulardan ba'zilari niqoblarga muhtoj, chunki ma'lum bitlar nazorat bitlari

*soniya = bcdToDec (Wire.read () & 0x7f); *daqiqa = bcdToDec (Wire.read ()); *soat = bcdToDec (Wire.read () & 0x3f); // Buni o'zgartirish kerak, agar soat 12:00/pm *dayOfWeek = bcdToDec (Wire.read ()); *dayOfMonth = bcdToDec (Wire.read ()); *oy = bcdToDec (Wire.read ()); *yil = bcdToDec (Wire.read ()); }

void drawText (OldString satri)

{dmd.clearScreen (haqiqiy); dmd.selectFont (Arial_Black_16); char newString [256]; int sLength = oldString.length (); oldString.toCharArray (newString, sLength+1); dmd.drawMarquee (newString, sLength, (32*DISPLAYS_ACROSS) -1, 0); uzoq boshlanish = millis (); uzoq taymer = boshlash; uzoq taymer2 = boshlash; mantiqiy ret = noto'g'ri; while (! ret) {if ((taymer+20) <millis ()) {ret = dmd.stepMarquee (-1, 0); taymer = millis (); }}}

void createTextTime (int ss, int mm)

// bu hamma vaqtdagi ma'lumotlarni bitta jumlaga aylantiradi {finalString = ""; // maxsus holatlar uchun jumlani o'chiring (pastda) finalString = finalString+"Bu";

// endi soatni qo'shing

agar (hh == 1 || hh == 13) {finalString = finalString+"bitta"; } if (hh == 2 || hh == 14) {finalString = finalString+"ikki"; } if (hh == 3 || hh == 15) {finalString = finalString+"uch"; } if (hh == 4 || hh == 16) {finalString = finalString+"to'rt"; } if (hh == 5 || hh == 17) {finalString = finalString+"besh"; } if (hh == 6 || hh == 18) {finalString = finalString+"olti"; } if (hh == 7 || hh == 19) {finalString = finalString+"etti"; } if (hh == 8 || hh == 20) {finalString = finalString+"sakkiz"; } if (hh == 9 || hh == 21) {finalString = finalString+"to'qqiz"; } if (hh == 10 || hh == 22) {finalString = finalString+"o'n"; } if (hh == 11 || hh == 23) {finalString = finalString+"o'n bir"; }

// endi daqiqalarni qo'shing

switch (mm) {1 -holat: finalString = finalString+"oh one"; tanaffus; 2 -holat: finalString = finalString+"oh ikki"; tanaffus; 3 -holat: finalString = finalString+"oh uch"; tanaffus; 4 -holat: finalString = finalString+"oh to'rt"; tanaffus; 5 -holat: finalString = finalString+"oh besh"; tanaffus; 6 -holat: finalString = finalString+"oh olti"; tanaffus; 7 -holat: finalString = finalString+"oh etti"; tanaffus; 8 -holat: finalString = finalString+"oh sakkiz"; tanaffus; 9 -holat: finalString = finalString+"oh to'qqiz"; tanaffus; 10 -holat: finalString = finalString+"o'n"; tanaffus; 11 -holat: finalString = finalString+"o'n bir"; tanaffus; 12 -holat: finalString = finalString+"o'n ikki"; tanaffus; 13 -holat: finalString = finalString+"o'n uch"; tanaffus; 14 -holat: finalString = finalString+"o'n to'rt"; tanaffus; 15 -holat: finalString = finalString+"o'n besh"; tanaffus; 16 -holat: finalString = finalString+"o'n olti"; tanaffus; 17 -holat: finalString = finalString+"o'n etti"; tanaffus; 18 -holat: finalString = finalString+"o'n sakkiz"; tanaffus; 19 -holat: finalString = finalString+"o'n to'qqiz"; tanaffus; 20 -holat: finalString = finalString+"yigirma"; tanaffus; 21 -holat: finalString = finalString+"yigirma bir"; tanaffus; 22 -holat: finalString = finalString+"yigirma ikki"; tanaffus; 23 -holat: finalString = finalString+"yigirma uch"; tanaffus; 24 -holat: finalString = finalString+"yigirma to'rt"; tanaffus; 25 -holat: finalString = finalString+"yigirma besh"; tanaffus; 26 -holat: finalString = finalString+"yigirma olti"; tanaffus; 27 -holat: finalString = finalString+"yigirma etti"; tanaffus; 28 -holat: finalString = finalString+"yigirma sakkiz"; tanaffus; 29 -holat: finalString = finalString+"yigirma to'qqiz"; tanaffus; 30 -holat: finalString = finalString+"o'ttiz"; tanaffus; 31 -holat: finalString = finalString+"o'ttiz bir"; tanaffus; 32 -holat: finalString = finalString+"o'ttiz ikki"; tanaffus; 33 -holat: finalString = finalString+"o'ttiz uch"; tanaffus; 34 -holat: finalString = finalString+"o'ttiz to'rt"; tanaffus; 35 -holat: finalString = finalString+"o'ttiz besh"; tanaffus; 36 -holat: finalString = finalString+"o'ttiz olti"; tanaffus; 37 -holat: finalString = finalString+"o'ttiz etti"; tanaffus; 38 -holat: finalString = finalString+"o'ttiz sakkiz"; tanaffus; 39 -holat: finalString = finalString+"o'ttiz to'qqiz"; tanaffus; 40 -holat: finalString = finalString+"qirq"; tanaffus; 41 -holat: finalString = finalString+"qirq bir"; tanaffus; 42 -holat: finalString = finalString+"qirq ikki"; tanaffus; 43 -holat: finalString = finalString+"qirq uch"; tanaffus; 44 -holat: finalString = finalString+"qirq to'rt"; tanaffus; 45 -holat: finalString = finalString+"qirq besh"; tanaffus; 46 -holat: finalString = finalString+"qirq olti"; tanaffus; 47 -holat: finalString = finalString+"qirq etti"; tanaffus; 48 -holat: finalString = finalString+"qirq sakkiz"; tanaffus; 49 -holat: finalString = finalString+"qirq to'qqiz"; tanaffus; 50 -holat: finalString = finalString+"ellik"; tanaffus; 51 -holat: finalString = finalString+"ellik bir"; tanaffus; 52 -holat: finalString = finalString+"ellik ikki"; tanaffus; 53 -holat: finalString = finalString+"ellik uch"; tanaffus; 54 -holat: finalString = finalString+"ellik to'rt"; tanaffus; 55 -holat: finalString = finalString+"ellik besh"; tanaffus; 56 -holat: finalString = finalString+"ellik olti"; tanaffus; 57 -holat: finalString = finalString+"ellik etti"; tanaffus; 58 -holat: finalString = finalString+"ellik sakkiz"; tanaffus; 59 -holat: finalString = finalString+"ellik to'qqiz"; tanaffus; }

// peshin?

if (hh == 12 && mm == 0) {finalString = finalString+"peshin"; } // yarim tunda? if (hh == 00 && mm == 0) {finalString = finalString+"yarim tunda"; }

}

bo'sh halqa ()

{// vaqtni RTC baytidan sekund, daqiqa, soat, dayOfWeek, dayOfMonth, oy, yil olish; getDateDs1307 (& ikkinchi, & daqiqa, & soat, & dayOfWeek, & dayOfMonth, & oy, & yil);

// vaqtni jumla qatoriga aylantiring

createTextTime (soat, daqiqa);

// endi matnni DMDga yuboring

drawText (finalString); }

Eskizda DS1307/3232 real vaqtli IC-laridan vaqtni belgilash va olishning odatiy funktsiyalari mavjud, va odatdagidek, bizning barcha soatlarimizda bo'sh vaqt parametrlarini bo'sh sozlamalarga kiritishingiz mumkin (), keyin esa setDateDs1307 () ga izoh bermang, eskizni yuklang, setDateDs1307 ga qayta sharh bering, so'ngra eskizni yana yuklang. Vaqtni qayta o'rnatish uchun protsedurani takrorlang, agar siz uskunaga asoslangan foydalanuvchi interfeysi qo'shmagan bo'lsangiz.

3 -qadam:

Vaqt void loop () da olinganidan so'ng, createTextTime () funktsiyasiga o'tkaziladi. Bu funksiya "Bu" bilan boshlanadigan matnli satrni yaratadi va joriy vaqtga qarab qaysi so'zlarga amal qilish kerakligini aniqlaydi. Nihoyat, drawText () funktsiyasi matnni ushlab turuvchi satrni DMDga uzatiladigan belgilar o'zgaruvchisiga aylantiradi.

Tavsiya: