Cov txheej txheem:

Arduino Scrolling Text Clock: 3 Kauj Ruam
Arduino Scrolling Text Clock: 3 Kauj Ruam

Video: Arduino Scrolling Text Clock: 3 Kauj Ruam

Video: Arduino Scrolling Text Clock: 3 Kauj Ruam
Video: Scrolling Matrix with Bluetooth and clock 2024, Kaum ib hlis
Anonim
Arduino Scrolling Text Clock
Arduino Scrolling Text Clock

Lub hom phiaj ntawm txoj haujlwm no yog txhawm rau tsim cov ntawv nyeem uas qhia lub sijhawm raws li nws tau hais (piv txwv li, "nws yog ib tag hmo").

Nov yog txoj haujlwm nrawm - peb muab rau koj txaus kom mus nrog kho vajtse thiab kos duab, thiab tom qab ntawd koj tuaj yeem siv nws ntxiv kom haum rau koj cov kev xav tau.

Kauj ruam 1: Kho vajtse

Kho vajtse
Kho vajtse

Koj yuav xav tau peb yam tseem ceeb -

  • ib pawg Arduino Uno-tau tshaj
  • lub sijhawm ua haujlwm ntawm lub moos lossis lub sijhawm siv lub DS1307 lossis DS3231 IC
  • thiab monochrome P10-style LED zaub

Tej zaum koj yuav xav tau lub zog hluav taws xob sab nraud, tab sis peb yuav mus txog qhov ntawd tom qab.

Thawj theem yog kom haum rau koj lub sijhawm tiag tiag. Nyem qhov no rau kev qhia yog tias koj xav tau kev pab nrog qhov ntawd.

Txog tam sim no kuv vam tias koj xav "koj yuav teem sijhawm li cas?".

Muaj ob lo lus teb rau lo lus nug ntawd. Yog tias koj siv DS3231 tsuas yog teeb nws hauv daim duab (saib hauv qab no) raws li qhov raug yog qhov zoo heev, koj tsuas yog yuav tsum xa cov duab kos nrog lub sijhawm tshiab ob zaug hauv ib xyoos kom them nyiaj nruab hnub.

Txwv tsis pub ntxiv cov neeg siv yooj yim-cuam tshuam-ob peb lub khawm tuaj yeem ua nws. Thaum kawg koj tsuas yog xav tau muab cov cuab yeej khoos phis tawj tso rau tom qab ntawm DMD. Muaj ntau txoj hauv kev kom tau raws li koj tus kheej cov kev xav tau, kev daws teeb meem yooj yim yuav yog txhawm rau tswj lub rooj tswj hwm kom koj tuaj yeem nkag mus rau lub qhov (socket) USB tau yooj yim - thiab tom qab ntawd lo nws nrog qee qhov Sugru.

Hais txog kev txhawb zog lub moos - koj tuaj yeem khiav ib qho LED pom los ntawm Arduino, thiab nws ua haujlwm ntawm qhov ci zoo rau siv sab hauv tsev. Yog tias koj xav kom DMD ua haujlwm puv ntoob, retina-ci ci koj yuav tsum siv cais 5V 4A DC fais fab mov cais. Yog tias koj siv ob DMDs - uas mus rau 8A, thiab ntxiv rau. Cias txuas lub zog sab nraud mus rau ib qho DMD lub davhlau ya nyob twg (txuas ob lossis ntau dua DMDs rau cov dav hlau no).

Yog tias koj tsis nyiam txiav qhov kawg ntawm koj lub xov tooj hluav taws xob, siv DC qhov ntsaws qhov tawg.

Kauj ruam 2: Arduino Sketch

Koj yuav tsum tau teeb tsa ob lub tsev qiv ntawv Arduino hauv qab no - TimerOne thiab DMD. Tom qab ntawd rub tawm daim duab:

// rau RTC #suav nrog "Wire.h" #define DS1307_I2C_ADDRESS 0x68 // DS1307 RTC yog 0x68

// rau LED zaub

#include "SPI.h" #include "DMD.h" #include "TimerOne.h" #include "SystemFont5x7.h" #include "Arial_black_16.h" #define DISPLAYS_ACROSS 1 // koj tuaj yeem muaj ntau dua ib qho DMD hauv kab #define DISPLAYS_DOWN 1 DMD dmd (DISPLAYS_ACROSS, DISPLAYS_DOWN);

Txoj hlua kawg // siv los tuav kab lus kawg kom pom ntawm DMD

void ScanDMD () // yuav tsum tau rau DMD

{dmd.scanDisplayBySPI (); }

void teeb tsa ()

{// rau DMD Timer1.initialize (5000); Timer1.attachInterrupt (ScanDMD); dmd.clearScreen (muaj tseeb);

// rau RTC

Hlau.begin (); // tua hluav taws I2C tsheb npav thib ob, feeb, teev, dayOfWeek, dayOfMonth, hli, xyoo; // hloov cov kev hloov pauv thiab tsis pom zoo setDateDs1307 los teeb lub sijhawm // tom qab ntawd rov tawm tswv yim tawm ntawm qhov ua haujlwm thiab xa cov duab kos dua zaum ob = 0; feeb = 13; teev = 23; dayOfWeek = 4; hnubOfMonth = 19; hli = 5; xyoo = 13; // setDateDs1307 (thib ob, feeb, teev, dayOfWeek, dayOfMonth, hli, xyoo); }

// ib txwm ua haujlwm RTC

// Hloov cov zauv zauv zauv rau zauv zauv zauv zauv zauv byte decToBcd (byte val) {rov qab ((val/10*16) + (val%10)); }

// Hloov cov lej zauv zauv zauv rau zauv zauv zauv

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

void setDateDs1307 (byte thib ob, // 0-59

byte feeb, // 0-59 byte teev, // 1-23 byte dayOfWeek, // 1-7 byte dayOfMonth, // 1-28/29/byte hli, // 1-12 byte xyoo) // 0- 99 {Wire.beginTransmission (DS1307_I2C_ADDRESS); Hlau.write (0); Wire.write (decToBcd (thib ob)); // 0 mus rau 7 pib lub moos Wire.write (decToBcd (feeb)); Wire.write (decToBcd (teev)); Wire.write (decToBcd (dayOfWeek)); Wire.write (decToBcd (dayOfMonth)); Wire.write (decToBcd (hli)); Wire.write (decToBcd (xyoo)); Wire.write (00010000); // xa 0x10 (hex) 00010000 (binary) los tswj kev sau npe - tig rau ntawm plaub fab plaub fab Wire.endTransmission (); }

// Tau txais hnub thiab sijhawm los ntawm ds1307

tsis muaj dab tsi getDateDs1307 (byte *thib ob, byte *feeb, byte *teev, byte *dayOfWeek, byte *dayOfMonth, byte *hli, byte *xyoo) {// Rov pib dua tus lej cim npe Wire.beginTransmission (DS1307_I2C_ADDRESS); Hlau.write (0); Wire.endTransmission ();

Wire.requestFrom (DS1307_I2C_ADDRESS, 7);

// Ob peb ntawm cov no xav tau daim npog qhov ncauj vim tias qee qhov me me yog tswj cov khoom

*thib ob = bcdToDec (Wire.read () & 0x7f); *feeb = bcdToDec (Wire.read ()); *teev = bcdToDec (Wire.read () & 0x3f); // Yuav tsum hloov qhov no yog 12 teev sawv ntxov/yav tsaus ntuj *dayOfWeek = bcdToDec (Wire.read ()); *dayOfMonth = bcdToDec (Wire.read ()); *hli = bcdToDec (Wire.read ()); *xyoo = bcdToDec (Wire.read ()); }

void drawText (Txoj hlua qub String)

{dmd.clearScreen (muaj tseeb); 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); ntev pib = millis (); timer ntev = pib; ntev timer2 = pib; boolean ret = tsis tseeb; thaum (! ret) {yog ((timer+20) <millis ()) {ret = dmd.stepMarquee (-1, 0); timer = millis (); }}}

tsis muaj dab tsi tsimTextTime (int hh, int mm)

// qhov no npog txhua lub sijhawm cov ntaub ntawv rau hauv kab ntawv raws li kab lus {finalString = ""; // so kab lus tawm rau cov xwm txheej tshwj xeeb (hauv qab) finalString = finalString+"Nws";

// tam sim no ntxiv cov teev

yog (hh == 1 || hh == 13) {finalString = finalString+"ib"; } yog (hh == 2 || hh == 14) {finalString = finalString+"ob"; } yog (hh == 3 || hh == 15) {finalString = finalString+"peb"; } yog (hh == 4 || hh == 16) {finalString = finalString+"plaub"; } yog (hh == 5 || hh == 17) {finalString = finalString+"tsib"; } yog (hh == 6 || hh == 18) {finalString = finalString+"six"; } yog (hh == 7 || hh == 19) {finalString = finalString+"xya"; } yog (hh == 8 || hh == 20) {finalString = finalString+"yim"; } yog (hh == 9 || hh == 21) {finalString = finalString+"cuaj"; } yog (hh == 10 || hh == 22) {finalString = finalString+"kaum"; } yog (hh == 11 || hh == 23) {finalString = finalString+"kaum ib"; }

// tam sim no ntxiv cov feeb

hloov (hli) {rooj plaub 1: finalString = finalString+"oh ib"; tawg; rooj plaub 2: finalString = finalString+"oh two"; tawg; rooj plaub 3: finalString = finalString+"oh peb"; tawg; rooj plaub 4: finalString = finalString+"oh plaub"; tawg; rooj plaub 5: finalString = finalString+"oh tsib"; tawg; rooj plaub 6: finalString = finalString+"oh six"; tawg; rooj plaub 7: finalString = finalString+"oh xya"; tawg; rooj plaub 8: finalString = finalString+"oh yim"; tawg; rooj plaub 9: finalString = finalString+"oh cuaj"; tawg; rooj plaub 10: finalString = finalString+"kaum"; tawg; rooj plaub 11: finalString = finalString+"kaum ib"; tawg; rooj plaub 12: finalString = finalString+"kaum ob"; tawg; rooj plaub 13: finalString = finalString+"kaum peb"; tawg; rooj plaub 14: finalString = finalString+"kaum plaub"; tawg; rooj plaub 15: finalString = finalString+"kaum tsib"; tawg; rooj plaub 16: finalString = finalString+"kaum rau"; tawg; rooj plaub 17: finalString = finalString+"kaum xya"; tawg; rooj plaub 18: finalString = finalString+"kaum yim"; tawg; rooj plaub 19: finalString = finalString+"cuaj caum"; tawg; rooj plaub 20: finalString = finalString+"nees nkaum"; tawg; rooj plaub 21: finalString = finalString+"nees nkaum ib"; tawg; rooj plaub 22: finalString = finalString+"nees nkaum ob"; tawg; rooj plaub 23: finalString = finalString+"nees nkaum peb"; tawg; rooj plaub 24: finalString = finalString+"nees nkaum plaub"; tawg; rooj plaub 25: finalString = finalString+"nees nkaum tsib"; tawg; rooj plaub 26: finalString = finalString+"nees nkaum rau"; tawg; rooj plaub 27: finalString = finalString+"nees nkaum xya"; tawg; rooj plaub 28: finalString = finalString+"nees nkaum yim"; tawg; rooj plaub 29: finalString = finalString+"nees nkaum cuaj"; tawg; rooj plaub 30: finalString = finalString+"peb caug"; tawg; rooj plaub 31: finalString = finalString+"peb caug ib"; tawg; rooj plaub 32: finalString = finalString+"peb caug ob"; tawg; rooj plaub 33: finalString = finalString+"peb caug peb"; tawg; rooj plaub 34: finalString = finalString+"peb caug plaub"; tawg; rooj plaub 35: finalString = finalString+"peb caug tsib"; tawg; rooj plaub 36: finalString = finalString+"peb caug rau"; tawg; rooj plaub 37: finalString = finalString+"peb caug xya"; tawg; rooj plaub 38: finalString = finalString+"peb caug yim"; tawg; rooj plaub 39: finalString = finalString+"peb caug cuaj"; tawg; rooj plaub 40: finalString = finalString+"plaub caug"; tawg; rooj plaub 41: finalString = finalString+"plaub caug ib"; tawg; rooj plaub 42: finalString = finalString+"plaub caug ob"; tawg; rooj plaub 43: finalString = finalString+"plaub caug peb"; tawg; rooj plaub 44: finalString = finalString+"plaub caug plaub"; tawg; rooj plaub 45: finalString = finalString+"plaub caug tsib"; tawg; rooj plaub 46: finalString = finalString+"plaub caug rau"; tawg; rooj plaub 47: finalString = finalString+"plaub caug xya"; tawg; rooj plaub 48: finalString = finalString+"plaub caug yim"; tawg; rooj plaub 49: finalString = finalString+"plaub caug cuaj"; tawg; rooj plaub 50: finalString = finalString+"tsib caug"; tawg; rooj plaub 51: finalString = finalString+"tsib caug ib"; tawg; rooj plaub 52: finalString = finalString+"tsib caug ob"; tawg; rooj plaub 53: finalString = finalString+"tsib caug peb"; tawg; rooj plaub 54: finalString = finalString+"tsib caug plaub"; tawg; rooj plaub 55: finalString = finalString+"tsib caug tsib"; tawg; rooj plaub 56: finalString = finalString+"tsib caug rau"; tawg; rooj plaub 57: finalString = finalString+"tsib caug xya"; tawg; rooj plaub 58: finalString = finalString+"tsib caug yim"; tawg; rooj plaub 59: finalString = finalString+"tsib caug cuaj"; tawg; }

// tav su?

yog (hh == 12 && mm == 0) {finalString = finalString+"midday"; } // ib tag hmo? yog (hh == 00 && mm == 0) {finalString = finalString+"ib tag hmo"; }

}

void lub voj ()

{// tau txais lub sijhawm los ntawm RTC byte thib ob, feeb, teev, dayOfWeek, dayOfMonth, hli, xyoo; getDateDs1307 (& thib ob, & feeb, & teev, & dayOfWeek, & dayOfMonth, & hli, & xyoo);

// hloov lub sijhawm rau kab lus kab lus

createTextTime (teev, feeb);

// tam sim no xa cov ntawv mus rau DMD

drawText (kab ntawv kawg); }

Cov duab kos muaj cov haujlwm ib txwm ua los teeb tsa thiab khaws lub sijhawm los ntawm DS1307/3232 lub sijhawm tiag tiag ICs, thiab raws li ib txwm muaj nrog peb txhua lub sijhawm koj tuaj yeem nkag mus rau lub sijhawm cov ntaub ntawv rau hauv qhov hloov pauv hauv qhov tsis muaj teeb tsa teeb tsa (), tom qab ntawv tsis suav nrog setDateDs1307 (), upload cov duab kos, rov hais dua setDateDs1307, tom qab ntawd rub cov duab kos ib zaug ntxiv. Rov ua cov txheej txheem ntawd kom rov teem sijhawm yog tias koj tsis tau ntxiv ib qho khoom siv kho vajtse raws li tus neeg siv.

Kauj ruam 3:

Thaum lub sijhawm tau txais hauv qhov tsis muaj dab tsi voj (), nws tau dhau mus rau txoj haujlwm createTextTime (). Txoj haujlwm no tsim cov kab ntawv kom pom los ntawm pib nrog "Nws", thiab tom qab ntawd txiav txim siab cov lus twg ua raws nyob ntawm lub sijhawm tam sim no. Thaum kawg txoj haujlwm drawText () hloov txoj hlua tuav cov ntawv los tso rau hauv tus yam ntxwv sib txawv uas tuaj yeem hla mus rau DMD.

Pom zoo: