Cov txheej txheem:

Christmas Music Cheer Light: 4 Kauj Ruam
Christmas Music Cheer Light: 4 Kauj Ruam

Video: Christmas Music Cheer Light: 4 Kauj Ruam

Video: Christmas Music Cheer Light: 4 Kauj Ruam
Video: Maroon 5 - Girls Like You ft. Cardi B (Official Music Video) 2024, Hlis ntuj nqeg
Anonim
Christmas Music Cheer Light
Christmas Music Cheer Light

Zoo siab heev Christmas! Koj puas xav muaj tsob ntoo Christmas uas tuaj yeem cuam tshuam nrog koj?

Kauj Ruam 1: Yam Khoom Siv Hauv Txoj Haujlwm no

Cov khoom siv kho vajtse

  • Seeeduino V4.2
  • Lub hauv paus ntaub thaiv npog V2
  • Grove - Hloov kho PIR Tsab Ntawv Pom Zoo Sensor
  • Grove - Lub suab nrov Sensor
  • Grove - WS2813 RGB LED Sawb Waterproof - 60 LED/m - 1m

Software apps thiab cov kev pabcuam online

Arduino IDE Cov

Kauj Ruam 2: Kev Kho Vajtse Txuas

Kho vajtse txuas
Kho vajtse txuas

Txuas PIR Sensor, Lub Suab nrov Sensor thiab LED sawb rau Base Shield qhov chaw nres nkoj D2, A0 thiab D6 cais. Plug Base Shield rau Seeduino, txhua yam ua tiav.

Kauj ruam 3: Software Programming

Cov tsev qiv ntawv hauv qab no xav tau los teeb tsa ua ntej ua haujlwm, thov rub tawm thiab xa lawv mus rau koj Arduino IDE tus kheej:

  • Coj_Strip
  • MsTimer2
  • Arduino_Vector

Txhawm rau ua kom txoj cai nruj dua, peb tau ntim nws. CheerLight chav kawm yog chav kawm thov ntawm txoj haujlwm no.

daim ntawv thov chav kawm:: CheerLight

: pej xeem daim ntawv thov:: interface:: IApplication {pej xeem: teeb tsa teeb tsa (tsis muaj dab tsi); void voj (tsis muaj dab tsi); void setPIRSensorPin (uint8_t tus pin); void setLoudnessSensorPin (uint8_t tus pin); void measureSensors (tsis muaj dab tsi); tsis muaj dab tsi pauvAnimation (tsis muaj dab tsi * args); void changeSpeed (tsis muaj dab tsi * args); void changeColor (tsis muaj dab tsi * args); daim ntawv thov zoo li qub:: CheerLight * getInstance (tsis muaj dab tsi); tiv thaiv: tsav tsheb:: LEDStrip _ledStrip; tsav:: PIRSensor _pirSensor; tsav tsheb:: LoudnessSensor _loudnessSensor; uint8_t _animation; middleware:: Delegate _detectedDelegate; middleware:: Delegate _absoluteLoudnessDelegate; middleware:: Delegate _relativeLoudnessDelegate; CheerLight (tsis muaj dab tsi); daim ntawv thov zoo li qub:: CheerLight _instance; };

CheerLight chav kawm tau tsim los ntawm Singleton Patterns, uas txhais tau tias tsuas muaj ib qho piv txwv rau nws, koj tuaj yeem hu rau CheerLight:: getInstance () rau qhov piv txwv ntawd. Yog tias koj qhov kev sib txuas ntawm Sensors sib txawv rau Kev Sib Txuas Kho Vajtse, koj tuaj yeem hloov lawv los ntawm kev hu xov tooj setPIRSensorPin () thiab setLoudnessSensorPin ().

Duab
Duab

Peb rov hais dua hu xov tooj measureSensors () txoj hauv kev ncua sijhawm los ua cov ntsuas ntsuas lub sijhawm, tab sis hu rau changeAnimation (), changeSpeed () lossis changeColor () cov txheej txheem manually tsis tsim nyog. Lawv yuav raug hu los ntawm Cov Neeg Sawv Cev thaum ntsuas ntsuas.

Tus Neeg Sawv Cev Yog Dab Tsi?

Raws li peb txhua tus paub, peb tuaj yeem tshaj tawm tus lej ua haujlwm thiab ua rau nws taw tes rau txoj haujlwm hauv C:

tsis muaj dab tsi func1 (tsis muaj dab tsi);

void (*pFunc) (tsis muaj dab tsi) = func1;

thiab siv nws los hu lub luag haujlwm nws taw tes rau

pFunc ();

Tab sis muaj qhov sib txawv hauv C ++, yog tias koj sim sau cov cai hauv qab no:

chav kawm A {

pej xeem: tsis muaj dab tsi func1 (tsis muaj dab tsi); }; void (*pFunc) (tsis muaj dab tsi) = & A:: func1;

tus compiler yuav tshaj tawm hom kev hloov pauv yuam kev, ntawm no yog qhov piv txwv raug:

void (A::*pFunc) (tsis muaj dab tsi) = & A:: func1;

Thaum peb sim siv nws los hu txoj kev ntawd, yuam kev dua. Qhov laj thawj rau qhov yuam kev ntawd yog qhov khoom-txheej txheem yuav tsum raug hu los ntawm ib qho khoom. Yog li peb tsim cov khoom kom hu nws:

A ib;

a.*pFunc ();

Lub sijhawm no tsis muaj teeb meem. Yog li muaj Delegate chav kawm hauv Delegate.h.

tus qauv

middleware chav kawm:: Delegate: public middleware:: interface:: IDelegate {public: Delegate (T *object, void (T:: *method) (void *)); void invoke (tsis muaj dab tsi * args); tiv thaiv: T * _object; tsis muaj dab tsi (T:: *_ txoj kev) (tsis muaj *); }; template inline middleware:: Delegate:: Delegate (T *object, void (T:: *method) (void *)): _object (object), _method (method) {} template inline void middleware:: Delegate:: thov (void * args) {(_object-> * _ method) (args); }

Vim tias Delegate chav kawm yog chav kawm qauv, uas txhais tau tias Delegate txawv rau Delegate, yuav ua li cas thiaj ua rau lawv taw qhia los ntawm tus pointer muaj tib yam? Cov lus teb yog interface, yog li muaj IDelegate interface hauv IDelegate.h.

middleware chav kawm:: interface:: IDelegate {

pej xeem: virtual void invoke (void * args) = 0; };

Hauv PIR Sensor thiab Loudness Sensor's chav kawm, muaj qhov sib txawv hu ua _delegates siv los khaws tus pointer ntawm Cov Neeg Sawv Cev, thiab muaj ib txoj hauv kev hu ua invokeAllDelegates () siv los hu rau txhua tus Delegates hauv _delegates, nws yuav raug hu ua ntsuas () txoj hauv kev.

NCO TSEG: Cov txheej txheem xa mus, xws li changeAnimation (), changeSpeed () thiab changeColor () yuav raug hu ua timer2 cuam tshuam, yog li tsis txhob siv ncua () lossis lwm yam cuam tshuam-raws li kev ua haujlwm hauv nws.

Pom zoo: