Orodha ya maudhui:

Saa ya Kutembeza ya Arduino: Hatua 3
Saa ya Kutembeza ya Arduino: Hatua 3

Video: Saa ya Kutembeza ya Arduino: Hatua 3

Video: Saa ya Kutembeza ya Arduino: Hatua 3
Video: Zuchu Amwaga Machozi Baada Ya kupewa Kiss Na Diamond Platinumz 2024, Novemba
Anonim
Saa ya Maandishi ya Arduino
Saa ya Maandishi ya Arduino

Madhumuni ya mradi huu ni kujenga saa ya maandishi ya kusogeza ambayo inaonyesha wakati kama inavyosemwa (kwa mfano, "ni usiku wa manane").

Huu ni mradi wa haraka - tunakupa vya kutosha kwenda na vifaa na mchoro, na kisha unaweza kuichukua zaidi kukidhi mahitaji yako.

Hatua ya 1: Vifaa

Vifaa
Vifaa

Utahitaji vitu vitatu vikuu -

  • bodi inayoendana na Arduino Uno
  • mzunguko wa saa halisi au moduli inayotumia DS1307 au DS3231 IC
  • na onyesho la LED la monochrome P10

Unaweza kutaka usambazaji wa umeme wa nje, lakini tutafika hapo baadaye.

Hatua ya kwanza ni kutoshea saa yako halisi. Bonyeza hapa kwa mafunzo ikiwa unahitaji msaada na hiyo.

Kwa sasa natumai unafikiria "unawekaje muda?".

Kuna majibu mawili kwa swali hilo. Ikiwa unatumia DS3231 tu iweke kwenye mchoro (angalia hapa chini) kwa kuwa usahihi ni mzuri sana, unahitaji tu kupakia mchoro na wakati mpya mara mbili kwa mwaka kufunika akiba ya mchana.

Vinginevyo ongeza kiolesura rahisi cha mtumiaji - vifungo kadhaa vinaweza kuifanya. Mwishowe unahitaji tu kuweka vifaa nyuma ya DMD. Kuna wigo mwingi wa kukidhi mahitaji yako mwenyewe, suluhisho rahisi inaweza kuwa kupangilia bodi ya kudhibiti ili uweze kufikia tundu la USB kwa urahisi - na kisha ubandike na Sugru.

Kuhusiana na kuwezesha saa - unaweza kukimbia onyesho moja la LED kutoka Arduino, na inaendesha mwangaza mzuri kwa matumizi ya ndani. Ikiwa unataka DMD iendeshe kwa ukamilifu, mwangaza unaowaka retina unahitaji kutumia umeme tofauti wa 5V 4A DC. Ikiwa unatumia DMD mbili - ambazo huenda kwa 8A, na kadhalika. Unganisha tu nguvu ya nje kwenye vituo vya DMD (unganisha vituo vya pili au zaidi kwa vituo hivi).

Ikiwa haupendi kukata mwisho wa kebo yako ya usambazaji wa umeme, tumia kuzuka kwa tundu la DC.

Hatua ya 2: Mchoro wa Arduino

Utahitaji kusanikisha maktaba mbili zifuatazo za Arduino - TimerOne na DMD. Kisha pakia mchoro:

// kwa RTC # ni pamoja na "Wire.h" #fafanua DS1307_I2C_ADDRESS 0x68 // DS1307 RTC ni 0x68

// kwa onyesho la LED

. safu #fafanua DISPLAYS_DOWN 1 DMD dmd (DISPLAYS_ACROSS, DISPLAYS_DOWN);

Kamba ya mwishoKamba; // kutumika kushikilia sentensi ya mwisho kuonyesha kwenye DMD

ScanDMD batili () // inahitajika kwa DMD

{dmd.scanDisplayBySPI (); }

kuanzisha batili ()

{/ kwa DMD Timer1.initialize (5000); Timer1.ambatanishaKukatisha (ScanDMD); dmd.clearScreen (kweli);

// kwa RTC

Wire.begin (); // zima moto I2C basi kwa sekunde, dakika, saa, sikuOfWeek, sikuOfMonth, mwezi, mwaka; // badilisha vigeuzi na uncomment setDateDs1307 kuweka wakati // kisha rejea maoni nje ya kazi na kupakia mchoro tena pili = 0; dakika = 13; saa = 23; sikuOfWeek = 4; sikuOfMonth = 19; mwezi = 5; mwaka = 13; // setDateDs1307 (pili, dakika, saa, sikuOfWeek, sikuOfMonth, mwezi, mwaka); }

// kazi za kawaida za RTC

// Kubadilisha nambari za kawaida za desimali kuwa baiti iliyosimbwa kwa nambari ya decToBcd (byte val) {kurudi ((val / 10 * 16) + (val% 10)); }

// Kubadilisha desimali iliyodhibitiwa kwa binary kuwa nambari za kawaida za desimali

byte bcdToDec (byte val) {kurudi ((val / 16 * 10) + (val% 16)); }

batili setDateDs1307 (byte pili, // 0-59

dakika ya baiti, // saa 0-59 byte, // siku 1 hadi 2 byteOfWeek, // siku ya 1 byteOfMonth, // 1-28 / 29 / byte month, // 1-12 byte year) // 0- 99 {Wire.beginTransmission (DS1307_I2C_ADDRESS); Andika waya (0); Wire.write (decToBcd (pili)); // 0 hadi kidogo 7 inaanza saa Wire.write (decToBcd (dakika)); Andika waya (decToBcd (saa)); Andika waya (decToBcd (sikuOfWeek)); Andika waya (decToBcd (sikuOfMonth)); Wire.write (decToBcd (mwezi)); Wire.write (decToBcd (mwaka)); Andika waya (00010000); // hutuma 0x10 (hex) 00010000 (binary) kudhibiti rejista - inageuka kwenye wimbi la waya la mraba. }

// Inapata tarehe na wakati kutoka kwa ds1307

batili ya kupataDateDs1307 (baiti * ya pili, dakika * dakika, saa * saa, siku ya sikuOfWeek, byte * sikuOfMonth, byte * mwezi, mwaka * mwaka) {// Rudisha rejista ya pointer Wire.beginTransmission (DS1307_I2C_ADDRESS); Andika waya (0); Uwasilishaji wa waya ();

Ombi la Wire. Toka (DS1307_I2C_ADDRESS, 7);

// Baadhi ya hizi zinahitaji masks kwa sababu bits fulani ni bits za kudhibiti

* pili = bcdToDec (Wire.read () & 0x7f); * dakika = bcdToDec (Wire.read ()); * saa = bcdToDec (Wire.read () & 0x3f); // Unahitaji kubadilisha hii ikiwa saa 12 asubuhi / jioni * dayOfWeek = bcdToDec (Wire.read ()); * sikuOfMonth = bcdToDec (Wire.read ()); * mwezi = bcdToDec (Wire.read ()); * mwaka = bcdToDec (Wire.read ()); }

DrawText batili (String oldString)

{dmd.clearScreen (kweli); dmd.selectFont (Arial_Black_16); char newString [256]; urefu s = urefuString.length (); oldString.toCharArray (newString, sLength + 1); dmd.drawMarquee (newString, sLength, (32 * ANAONYESHA_ACROSI) -1, 0); kuanza kwa muda mrefu = millis (); muda mrefu = kuanza; muda mrefu2 = kuanza; boolean ret = uwongo; wakati (! ret) {if ((timer + 20) <millis ()) {ret = dmd.stepMarquee (-1, 0); kipima muda = millis (); }}}

tupu kuundaTextTime (int hh, int mm)

// hii inasanya data ya wakati wote kuwa maandishi kama sentensi moja {finalString = ""; // futa hukumu kwa kesi maalum (chini) finalString = finalString + "Ni";

// sasa ongeza saa

ikiwa (hh == 1 || hh == 13) {finalString = finalString + "one"; } ikiwa (hh == 2 || hh == 14) {finalString = finalString + "mbili"; } ikiwa (hh == 3 || hh == 15) {finalString = finalString + "tatu"; } ikiwa (hh == 4 || hh == 16) {finalString = finalString + "four"; } ikiwa (hh == 5 || hh == 17) {finalString = finalString + "tano"; } ikiwa (hh == 6 || hh == 18) {finalString = finalString + "six"; } ikiwa (hh == 7 || hh == 19) {finalString = finalString + "saba"; } ikiwa (hh == 8 || hh == 20) {finalString = finalString + "nane"; } ikiwa (hh == 9 || hh == 21) {finalString = finalString + "tisa"; } ikiwa (hh == 10 || hh == 22) {finalString = finalString + "ten"; } ikiwa (hh == 11 || hh == 23) {finalString = finalString + "eleven"; }

// sasa ongeza dakika

kubadili (mm) {kesi 1: finalString = finalString + "oh one"; kuvunja; kesi 2: finalString = finalString + "oh mbili"; kuvunja; kesi 3: finalString = finalString + "oh tatu"; kuvunja; kesi 4: finalString = finalString + "oh nne"; kuvunja; kesi 5: finalString = finalString + "oh tano"; kuvunja; kesi 6: finalString = finalString + "oh six"; kuvunja; kesi 7: finalString = finalString + "oh saba"; kuvunja; kesi 8: finalString = finalString + "oh nane"; kuvunja; kesi 9: finalString = finalString + "oh tisa"; kuvunja; kesi 10: finalString = finalString + "ten"; kuvunja; kesi 11: finalString = finalString + "kumi na moja"; kuvunja; kesi 12: finalString = finalString + "kumi na mbili"; kuvunja; kesi 13: finalString = finalString + "kumi na tatu"; kuvunja; kesi 14: finalString = finalString + "kumi na nne"; kuvunja; kesi 15: finalString = finalString + "kumi na tano"; kuvunja; kesi 16: finalString = finalString + "kumi na sita"; kuvunja; kesi 17: finalString = finalString + "kumi na saba"; kuvunja; kesi 18: finalString = finalString + "kumi na nane"; kuvunja; kesi 19: finalString = finalString + "kumi na tisa"; kuvunja; kesi 20: finalString = finalString + "ishirini"; kuvunja; kesi 21: finalString = finalString + "ishirini na moja"; kuvunja; kesi 22: finalString = finalString + "ishirini na mbili"; kuvunja; kesi 23: finalString = finalString + "ishirini na tatu"; kuvunja; kesi 24: finalString = finalString + "ishirini na nne"; kuvunja; kesi 25: finalString = finalString + "ishirini na tano"; kuvunja; kesi 26: finalString = finalString + "ishirini na sita"; kuvunja; kesi 27: finalString = finalString + "ishirini na saba"; kuvunja; kesi 28: finalString = finalString + "ishirini na nane"; kuvunja; kesi 29: finalString = finalString + "ishirini na tisa"; kuvunja; kesi 30: finalString = finalString + "thelathini"; kuvunja; kesi 31: finalString = finalString + "thelathini na moja"; kuvunja; kesi 32: finalString = finalString + "thelathini na mbili"; kuvunja; kesi 33: finalString = finalString + "thelathini na tatu"; kuvunja; kesi 34: finalString = finalString + "thelathini na nne"; kuvunja; kesi 35: finalString = finalString + "thelathini na tano"; kuvunja; kesi 36: finalString = finalString + "thelathini na sita"; kuvunja; kesi 37: finalString = finalString + "thelathini na saba"; kuvunja; kesi 38: finalString = finalString + "thelathini na nane"; kuvunja; kesi 39: finalString = finalString + "thelathini na tisa"; kuvunja; kesi 40: finalString = finalString + "arobaini"; kuvunja; kesi 41: finalString = finalString + "arobaini na moja"; kuvunja; kesi 42: finalString = finalString + "arobaini na mbili"; kuvunja; kesi 43: finalString = finalString + "arobaini na tatu"; kuvunja; kesi 44: finalString = finalString + "arobaini na nne"; kuvunja; kesi 45: finalString = finalString + "arobaini na tano"; kuvunja; kesi 46: finalString = finalString + "arobaini na sita"; kuvunja; kesi 47: finalString = finalString + "arobaini na saba"; kuvunja; kesi 48: finalString = finalString + "arobaini na nane"; kuvunja; kesi 49: finalString = finalString + "arobaini na tisa"; kuvunja; kesi 50: finalString = finalString + "hamsini"; kuvunja; kesi 51: finalString = finalString + "hamsini na moja"; kuvunja; kesi 52: finalString = finalString + "hamsini na mbili"; kuvunja; kesi 53: finalString = finalString + "hamsini na tatu"; kuvunja; kesi 54: finalString = finalString + "hamsini na nne"; kuvunja; kesi 55: finalString = finalString + "hamsini na tano"; kuvunja; kesi 56: finalString = finalString + "hamsini na sita"; kuvunja; kesi 57: finalString = finalString + "hamsini na saba"; kuvunja; kesi 58: finalString = finalString + "hamsini na nane"; kuvunja; kesi 59: finalString = finalString + "hamsini na tisa"; kuvunja; }

// saa sita mchana?

ikiwa (hh == 12 && mm == 0) {finalString = finalString + "midday"; } // usiku wa manane? ikiwa (hh == 00 && mm == 0) {finalString = finalString + "midnight"; }

}

kitanzi batili ()

{// pata muda kutoka kwa baiti ya RTC sekunde, dakika, saa, sikuOfWeek, sikuOfMonth, mwezi, mwaka; getDateDs1307 (& pili, & dakika, & saa, & sikuOfWeek, & dayOfMonth, & month, & year);

// kubadilisha wakati kuwa kamba ya sentensi

tengenezaTextTime (saa, dakika);

// sasa tuma maandishi kwa DMD

DrawText (finalString); }

Mchoro una kazi za kawaida za kuweka na kupata wakati kutoka kwa ICs za saa halisi za DS1307 / 3232, na kama kawaida na saa zetu zote unaweza kuingiza habari ya wakati katika anuwai katika usanidi batili (), halafu uncomment setDateDs1307 (), pakia mchoro, toa maoni tena setDateDs1307, halafu pakia mchoro tena. Rudia mchakato huo kuweka tena wakati ikiwa haukuongeza kiolesura chochote cha watumiaji kinachotegemea vifaa.

Hatua ya 3:

Mara tu wakati unapopatikana katika kitanzi batili (), hupitishwa kwa kazi ya kuundaTextTime (). Kazi hii huunda kamba ya maandishi kuonyesha kwa kuanza na "Ni", na kisha huamua ni maneno gani ya kufuata kulingana na wakati wa sasa. Mwishowe kazi ya kutekaText () inabadilisha kamba iliyoshikilia maandishi kuonyesha kuwa anuwai ya tabia ambayo inaweza kupitishwa kwa DMD.

Ilipendekeza: