Cov txheej txheem:

Arduino Tone Generator Tsis Muaj Lub Tsev Qiv Ntawv lossis Cov Haujlwm Ua Haujlwm (Nrog cuam tshuam): 10 Cov Kauj Ruam
Arduino Tone Generator Tsis Muaj Lub Tsev Qiv Ntawv lossis Cov Haujlwm Ua Haujlwm (Nrog cuam tshuam): 10 Cov Kauj Ruam

Video: Arduino Tone Generator Tsis Muaj Lub Tsev Qiv Ntawv lossis Cov Haujlwm Ua Haujlwm (Nrog cuam tshuam): 10 Cov Kauj Ruam

Video: Arduino Tone Generator Tsis Muaj Lub Tsev Qiv Ntawv lossis Cov Haujlwm Ua Haujlwm (Nrog cuam tshuam): 10 Cov Kauj Ruam
Video: NOOBS PLAY CLASH ROYALE FROM START LIVE 2024, Hlis ntuj nqeg
Anonim
Arduino Tone Generator Tsis Muaj Lub Tsev Qiv Ntawv lossis Cov Haujlwm Ua Haujlwm (Nrog cuam tshuam)
Arduino Tone Generator Tsis Muaj Lub Tsev Qiv Ntawv lossis Cov Haujlwm Ua Haujlwm (Nrog cuam tshuam)

Qhov no tsis yog ib yam uas kuv ib txwm ua qhia rau, Kuv nyiam kuv cov khoom siv hlau, tab sis raws li kuv yog cov tub ntxhais kawm siv hluav taws xob thiab yuav tsum kawm chav kawm ntawm microcontrollers (Embedded Systems Design), Kuv xav tias kuv yuav ua tus qhia rau ib qho ntawm kuv cov haujlwm. Thaum kuv xub tsim txoj haujlwm thiab lwm tus rau chav kawm no, Kuv pom tias muaj tsawg heev rau yam tsis muaj kev qhia uas tsis siv lub tsev qiv ntawv arduino ua haujlwm lossis cov haujlwm ua haujlwm, uas yog lwm qhov laj thawj kuv xav tias qhov no yuav yog kev qhia zoo.

Cov cai no tau tsim los rau Atmega 2560 microcontroller, yog li yog tias koj xav siv nws ntawm lwm lub rooj tsav xwm koj yuav xav hloov qhov chaw sau npe hauv cov cai raws li koj tus tswj kev siv phau ntawv. Lub tswv yim yooj yim tom qab txoj cai yog tias thaum twg koj nkag mus rau qhov tseem ceeb ntawm cov keyboard rau hauv lub tshuab saib xyuas, lub arduino mega yuav tso tawm qee qhov zaus raws li tus yuam sij koj nias, nrog "q" rov pib dua nws. Kuv ua nws kom "a" yuav tso tawm A zaus zaus thiab "A" yuav tso tawm A zaus nrawm, "b" tso tawm B tiaj tus, "c" rau C tiaj, "C" rau C ntse, thiab ntxiv rau. Cov lej tag nrho tau muab tso rau thaum kawg, tab sis txhua kauj ruam yuav ua txhaum cov cai rau hauv daim kom nws yooj yim los piav qhia.

Kauj Ruam 1: Txheeb Npe Chaw Nyob

Txhais Chaw Sau Npe
Txhais Chaw Sau Npe

Cov kauj ruam no yooj yim, yog tias koj siv atmega 2560, koj tsuas yog xav siv qhov chaw nyob uas kuv tau siv, txawm hais tias yog koj siv lub rooj tsavxwm nrog cov chip sib txawv, koj yuav tsum nrhiav qhov chaw nyob rau txhua qhov ntawm cov npe no ntawm koj chips 'neeg siv phau ntawv. Cov lus piav qhia saum toj kawg nkaus tsuas yog qhov uas yuav siv rau peb cov haujlwm tom qab. Peb hais qhia qhov chaw nyob raws li qhov hloov pauv tsis tau kos npe vim tias peb tsis xav kom tus neeg sau ua ke cuam tshuam nrog lawv.

Kauj Ruam 2: Arrays thiab Cov Hloov Ntiaj Teb

Arrays thiab Global Variables
Arrays thiab Global Variables
Arrays thiab Global Variables
Arrays thiab Global Variables
Arrays thiab Global Variables
Arrays thiab Global Variables

Ntawm no peb xav kom txheeb xyuas qhov zaus zaus uas yuav muaj tag nrho cov zaus uas txhua tus yuam sij yuav tsum tso tawm. Cov txiaj ntsig no tau suav los ntawm qhov nco tseg ntau zaus, thiab ua siab ncaj kuv tsis nco qab tias kuv tau txais lawv li cas, tab sis lawv yog qhov raug qhov raug raws li kuv tau sim lawv ntawm oscilloscope kom paub tseeb. Peb kuj tseem txheeb xyuas cov ntawv sau sau uas muaj tag nrho cov yuam sij los nias rau txhua lub suab, nrog rau cov kev hloov pauv uas peb xav tau rau peb cov haujlwm tom qab.

Kauj Ruam 3: Qhov "serial.begin" Muaj nuj nqi

Cov
Cov

Peb yuav hu peb cov kev cai uas rov ua dua "serial.begin" ua haujlwm U0init (). Nws yuav siv qhov xav tau baudrate raws li cov tswv yim thiab pib qhov chaw nres nkoj ntawm qhov baudrate.

Kauj Ruam 4: Qhov "serial.available" Function

Cov
Cov

Peb yuav hu lub luag haujlwm uas ua raws "serial.available" U0kbhit (). Nws tsis siv cov tswv yim tab sis hloov pauv pom yog tias muaj kev hloov pauv ntawm cov keyboard siv RDA xwm txheej me ntsis thiab rov muaj tseeb thaum pom qhov hloov pauv.

Kauj Ruam 5: Qhov "serial.read" Muaj nuj nqi

Cov
Cov

Peb yuav hu lub luag haujlwm uas ua raws li "serial.read" muaj nuj nqi U0getchar (), uas tsis siv cov tswv yim thiab tso tawm qhov hloov pauv dab tsi ntawm cov keyboard, uas tau khaws cia hauv UDR0 rau npe.

Kauj Ruam 6: Qhov "serial.write" Muaj nuj nqi

Cov
Cov

Peb yuav hu lub luag haujlwm uas ua piv txwv "serial.write" U0putchar (), uas siv cov ntaub ntawv los ntawm UDR0 sau npe thaum hloov pauv raug kuaj pom thiab khaws cia, thiab cov txiaj ntsig uas hloov rov qab mus rau tus saib xyuas.

Kauj Ruam 7: Teeb Ua Haujlwm

Teeb Teeb
Teeb Teeb

Qhov no yog qhov teeb tsa ua haujlwm yooj yim uas yuav siv peb "serial.begin" kev coj ua kom pib qhov chaw nres nkoj, thiab yuav pib ua ntej peb teeb tsa me ntsis rau lub sijhawm teev npe thiab teeb tsa PB6 kom tso tawm peb lub suab nrov.

Kauj Ruam 8: Lub Loop thiab ISR Cov Haujlwm

Lub Loop thiab ISR Cov Haujlwm
Lub Loop thiab ISR Cov Haujlwm

Lub voj ua haujlwm zoo li no: yog tias pom muaj kev hloov pauv nrog peb "serial.available" muaj nuj nqi, peb "serial.read" cov khw muag khoom muaj nuj nqis uas hloov pauv, thiab peb "serial.write" muaj nuj nqi tso qhov kev hloov pauv ntawd mus rau hauv cov saib. Tsuav yog qhov sib txawv kuv tsawg dua qhov loj ntawm qhov ntau zaus, nws yuav teeb tsa qhov tso tawm kom yog txoj haujlwm ntawm i hauv qhov array, tso tawm qhov zaus ntawm txoj haujlwm ntawd. ISR ua haujlwm raws li kev rov pib dua, qhov twg yog qhov chaw ua haujlwm zaus tsis sib npaug 0 (hauv lwm lo lus yog "q" tsis raug nias), nws yuav tso tawm zaus, tab sis thaum "q" raug nias nws yuav rov pib dua. txoj cai no siv kev cuam tshuam, tab sis nws tuaj yeem ua tiav nrog cuam tshuam cuam tshuam. Kuv yuav tshaj tawm cov cai yam tsis muaj cuam tshuam yog tias kuv tau txais kev thov rau nws, Kuv tsuas yog xav tias qhov cuam tshuam version yog lom zem dua.

Kauj Ruam 9: Txuas kab

Thaiv
Thaiv

Txoj hlua rau tus lej no yooj yim heev, tsuas yog muab cov xov hluav taws xob los ntawm PB6 mus rau lub khob cij, txuas lub suab nrov lossis hais lus hauv kab lus nrog qhov ntawd, thiab txuas nws rov qab rau hauv av. Nco tseg: yog tias koj siv tus hais lus, muab lub me me tiv thaiv ua ntej tus hais lus. Yog tias koj tsuas yog xav pom qhov tso tawm tab sis tsis hnov nws, tsuas yog txuas PB6 mus rau cov hlau lead liab ntawm oscilloscope thiab cov hlau lead dub rau hauv av.

Kauj Ruam 10: Muab Nws Ua Ke

Kuv tau ntxiv tag nrho cov cai rau cov kauj ruam no, txij li kuv tau piav qhia txhua qhov ntawm nws hauv cov kauj ruam dhau los. Nws tsuas yog siv cov keyboard nkag rau ntau qhov sib txawv thiab tso tawm qhov zaus mus rau PB6. Vam tias koj nyiam nyeem lwm txoj hauv kev rau tus lej nrog IDE!

Tsis tas li, thov pov npav rau qhov no hauv kev sib tw Microcontroller: D

Pom zoo: