Cov txheej txheem:
- Kauj Ruam 1: Teeb tsa Pawg Thawj Coj
- Kauj ruam 2: Ntxiv khawm thiab Resistor
- Kauj Ruam 3: Khawm Sib Txuas
- Kauj ruam 4: Txoj Cai…
- Kauj ruam 5: Me ntsis Debounce
- Kauj Ruam 6: Ua Cov Ntawv Qhia
- Kauj Ruam 7: Txoj Cai Rhuav - Ntiaj Teb
- Kauj Ruam 8: Txoj Cai Rhuav - Teeb thiab Kev Ua Haujlwm Tshwj Xeeb
- Kauj Ruam 9: Lub Loop…
- Kauj Ruam 10: Kawg Txoj Cai Thaiv
Video: Cov Ntawv Qhia zaub mov hauv Arduino, thiab Yuav Siv Cov Khawm Li Cas: 10 Kauj Ruam (nrog Duab)
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:27
Hauv kuv qhov Arduino 101 qhia, koj yuav raug qhia paub teeb tsa koj ib puag ncig hauv Tinkercad li cas. Kuv siv Tinkercad vim tias nws yog lub zog zoo hauv online uas tso cai rau kuv los qhia ntau yam txuj ci rau cov tub ntxhais kawm rau kev tsim vaj tsev. Xav tias dawb los tsim txhua qhov kuv qhia siv Arduino IDE thiab Arduino tiag!
Hauv qhov kev qhia no, peb yuav kawm paub txog cov nyees khawm! Peb yuav tsum paub:
- Yuav ua li cas xaim lawv
- Nyeem lawv tus nqi
- Debounce, thiab vim li cas nws thiaj tseem ceeb
- Daim ntawv thov siv tau (tsim cov ntawv qhia zaub mov)
Cov neeg feem coob xav tias qhov ua tau zoo tshaj plaws ua nrog khawm yog qhib lub teeb thiab tua. Peb yuav, tsis nyob ntawm no! Peb yuav siv peb li los tsim cov ntawv qhia zaub mov thiab teeb tsa qee qhov kev xaiv ntawm Arduino.
Npaj? Cia peb pib!
Kauj Ruam 1: Teeb tsa Pawg Thawj Coj
Thawj kauj ruam yog tso Arduino thiab Breadboard Small mus rau thaj chaw tsim qauv. Txheeb xyuas cov duab saum toj no kom pom yuav ua li cas xaim cov kab hluav taws xob.
Breadboard Mini muaj ob lub hwj chim ntsia saum thiab hauv qab. Peb xaim cov no mus rau Arduino yog li peb tuaj yeem muab lub zog rau ntau yam ntxiv. Tom qab hauv qhov kev qhia no peb yuav siv 3 khawm kom peb yuav xav tau lub zog ntau dua. Qhov yuav tsum tau nco yog tias ntawm lub khob cij me me, lub zog fais fab hla lub rooj tsavxwm, kab rov tav. Qhov no txawv ntawm kab nyob hauv thaj tsam tseem ceeb hauv nruab nrab; cov no khiav ntsug. Koj tuaj yeem siv ib qho ntawm lub hwj chim los muab lub zog rau txhua kab hauv thaj chaw tseem ceeb hauv nruab nrab.
Thaum koj ntxiv lub zog, siv cov xov dub thiab liab rau qhov tsis zoo thiab zoo ib yam. Ntxiv cov xov hlau ntawm qhov kawg uas khiav lub zog mus rau lwm sab ntawm lub rooj tsavxwm. Peb yuav tsis siv sab ntawd, tab sis nws yog kev xyaum zoo.
Kauj ruam 2: Ntxiv khawm thiab Resistor
Ntxiv lub pob me me los ntawm cov khoom ntim khoom. Nws yuav tsum zoo li tus nyob hauv daim duab. Nco ntsoov tias nws tsis yog qhov hloov pauv! Ntxiv ib tus resistor, ib yam nkaus. Nyem nws, thiab teeb nws tus nqi rau 10kΩ. Qhov ntawd txaus los rub tus pin qis thaum nws tsis txuas nrog, uas yog qhov tseem ceeb heev tom qab hauv cov cai.
Muab cov khoom pov tseg hla nruab nrab ntawm daim ntawv qhia zaub mov. Txoj hauv kev khawm ua haujlwm yog:
- Kaum rau kaum, khawm tsis txuas nrog. Thawb lub pob kaw cov neeg sib txuas thiab txuas cov ces kaum.
- Ob sab ntawm lub khawm txuas nrog. Yog tias koj txuas lub xaim mus rau sab laug sab saum toj thiab hauv qab sab laug, lub Circuit Court yuav raug kaw.
Qhov no yog vim li cas peb tso cov khoom tiv thaiv thoob plaws qhov chaw hauv nruab nrab. Nws ua kom ntseeg tau tias cov ces kaum tsis txuas nrog hauv qab tus pin hauv pawg thawj coj saib.
Cov kauj ruam tom ntej muab ob peb cov duab uas qhia txog cov ntsiab lus no.
Muab tus tiv thaiv los ntawm tus hauv qab txoj cai tus pin hla txhua kab, yog li nws zaum ntawm kab rov tav.
Kauj Ruam 3: Khawm Sib Txuas
Cov duab saum toj no ua kom pom tseeb tias cov nyees khawm txuas li cas. Nws ib txwm yog lub ntsiab lus tsis meej pem thaum koj xav tias txhua yam zoo thiab nws tsis ua haujlwm!
Tam sim no, cia peb ntxiv cov xov hlau.
- Muab cov hlau lead liab los ntawm tus lej fais fab zoo rau tib kab ntawv zoo li tus lej hauv qab ntawm tus khawm
- Muab cov hlau lead dub los ntawm tus pin tsis zoo rau tib kab ntawv raws li tus tiv thaiv.
- Muab cov xaim xim (tsis liab/dub) los ntawm tus pin sab laug rau Digital Pin 2 ntawm Arduino
Txheeb xyuas cov duab saum toj no kom ntseeg tau tias koj cov xov hlau raug.
Kauj ruam 4: Txoj Cai…
Cia peb saib cov cai rau lub hauv paus khawm.
Qhib tus kws kho qhov chaws thiab hloov pauv los ntawm Blocks rau Text. Tshem cov lus ceeb toom uas tuaj. Peb zoo siab nrog cov ntawv!
Koj paub qhov teeb tsa yooj yim, yog li cia txhais lub pob thiab ua qhov nyeem yooj yim. Peb yuav luam tawm cov ntawv rau Serial.
Kuv muab ob peb cov lus ntxiv rau hauv cov cai hauv qab no kom nws yooj yim nyeem dua li cov duab.
// Txheeb cais
#define khawm 2 tsis muaj teeb tsa teeb tsa () {pinMode (khawm, INPUT); Serial.begin (9600); } void loop () {// Nyeem tus lej digital txhawm rau txheeb xyuas qhov xwm txheej ntawm khawm int nias = digitalRead (khawm); // Khawm rov qab HIGH yog nias, LOW yog tias tsis yog (nias == HIGH) {Serial.println ("Nias!"); }}
Ok, zoo uas ua haujlwm!
Qhov tseem ceeb, txhua yam peb tab tom ua yog txheeb xyuas qhov xwm txheej ntawm tus lej digital txhua lub sijhawm cov lej loops. Yog tias koj nyem Pib Simulation thiab nias lub pob, koj yuav pom Serial Monitor (nyem lub pob hauv qab cov cai) tso saib "Nias!" ntau zaus.
Ib qho tshwj xeeb uas koj yuav pom hauv cov cai saum toj no yog yog () kev tshuaj xyuas qhov xwm txheej. Txhua txoj cai tau ua yog nug cov lus nug thiab tshuaj xyuas yog tias nws muaj tseeb, hauv qhov no. Peb siv qhov sib npaug (ob npaug sib npaug cim, zoo li no: ==) txhawm rau txheeb xyuas yog tias tus nqi ntawm qhov sib txawv sib npaug nrog tus nqi tshwj xeeb. DigitalRead () rov qab los siab lossis qis.
Siv qhov yog () lwm yam yog / lwm yam peb tuaj yeem tshawb xyuas ntau yam xwm txheej lossis txhua yam xwm txheej, thiab yog tias koj rov qab mus rau Arduino Basics, koj yuav pom qee qhov kev sib piv uas koj tuaj yeem ua.
Tam sim no… Peb cov cai yuav zoo ua tiav… Tab sis peb muaj teeb meem.
Saib, uas ua haujlwm tau zoo tiag tiag thaum nyob hauv lub simulator. Tab sis hluav taws xob tiag tiag muaj suab nrov, tshwj xeeb yog DC cov khoom siv hluav taws xob. Yog li peb lub khawm yuav rov qab nyeem tsis raug qee zaum. Thiab qhov teeb meem, vim tias koj txoj haujlwm yuav tsis teb raws txoj cai rau tus neeg siv.
Wb kho nws!
Kauj ruam 5: Me ntsis Debounce
Peb siv cov txheej txheem hu ua debounce kom kov yeej peb cov teeb meem khawm. Qhov no yeej tseem tos sijhawm tshwj xeeb ntawm lub sijhawm thaum lub khawm raug thawb thiab ua tau zoo rau lub laub. Nws tseem zoo li ntuj rau tus neeg siv (tshwj tsis yog koj ua lub sijhawm ntev dhau). Koj kuj tseem tuaj yeem siv nws txhawm rau txheeb xyuas qhov ntev ntawm xovxwm, yog li koj tuaj yeem teb txawv txhua lub sijhawm. Koj tsis tas yuav hloov ib qho ntawm cov thaiv!
Wb saib cov cai:
#define khawm 2#txhais debounceTimeout 100
Thawj qhov kev hloov pauv yog nyob thoob ntiaj teb. Koj yuav nco ntsoov qhov ntawd yog qhov uas peb piav qhia ntau yam ntawm peb cov haujlwm yuav siv lossis cov uas tsis tuaj yeem rov pib dua txhua lub sijhawm lub voj hluav taws. Yog li, peb tau ntxiv debounceTimeout rau qhov txuas ntxiv. Peb tau ua 100 qhov no (uas tom qab yuav txhais mus rau 100ms), tab sis nws tuaj yeem luv dua. Ib qho ntxiv thiab nws yuav hnov qhov tsis zoo.
ntev int lastDebounceTime;
Qhov sib txawv no tau tshaj tawm hauv qab qhov tsis tu ncua. Qhov no yog hom ntev ntev, uas ib txwm tso cai rau peb khaws cov lej ntev hauv lub cim xeeb. Peb hu nws ua LastDebounceTime.
Peb tsis tas yuav hloov dab tsi hauv qhov tsis muaj teeb tsa teeb tsa () muaj nuj nqi. Cia peb tawm qhov ntawd.
void loop () {// Nyeem tus lej digital txhawm rau txheeb xyuas qhov xwm txheej ntawm khawm int nias = digitalRead (khawm); ntev int currentTime = millis (); // Khawm code}
Thawj qhov kev hloov pauv peb ua hauv lub voj () muaj nuj nqi yog nyob rau hauv kev hu kom nyeem lub pob. Peb yuav tsum tau taug qab lub sijhawm tam sim no. Millis () muaj nuj nqi rov qab rau lub sijhawm tam sim no ntawm lub moos txij li Arduino tau pib ua haujlwm hauv milliseconds. Peb yuav tsum khaws qhov no hauv qhov ntev int yam sib txawv.
Tam sim no, peb yuav tsum paub tseeb tias peb tau paub txog lub sijhawm txij li lub pob raug nias, yog li peb rov pib lub sijhawm thaum nws tsis nias. Ua tib zoo saib:
void loop () {// Nyeem tus lej digital txhawm rau txheeb xyuas qhov xwm txheej ntawm khawm int nias = digitalRead (khawm); ntev int currentTime = millis (); yog (nias == LOW) {// Rov pib suav lub sijhawm thaum lub khawm tsis nias lastDebounceTime = tam sim noTime; } // Khawm code}
Yog tias (nias == LOW) txheej txheem tshuaj xyuas yog tias lub pob tsis raug nias. Yog tias nws tsis yog, tom qab ntawv tus lej khaws lub sijhawm tam sim no txij li kev tshaj tawm zaum kawg. Txoj kev ntawd, txhua lub sijhawm nias lub pob, peb muaj lub ntsiab lus nyob rau lub sijhawm uas peb tuaj yeem tshawb xyuas thaum lub pob raug nias. Peb tuaj yeem ua qhov laij lej sai kom pom lub pob tau ntev npaum li cas, thiab teb kom raug. Cia peb saib qhov seem ntawm cov cai:
void loop () {// Nyeem tus lej digital txhawm rau txheeb xyuas qhov xwm txheej ntawm khawm int nias = digitalRead (khawm); ntev int currentTime = millis (); yog (nias == LOW) {// Rov pib suav lub sijhawm thaum lub khawm tsis nias lastDebounceTime = tam sim noTime; } // Khawm tau raug nias rau lub sijhawm muab yog ((((Tam sim noTime - lastDebounceTime)> debounceTimeout)) {// Yog tias lub sijhawm dhau mus, khawm nias! Serial.println ("Nias!"); }}
Qhov kawg ntawm cov cai siv lub sijhawm tam sim no, rho tawm lub sijhawm debounce zaum kawg thiab muab piv rau lub sijhawm uas peb tau teem tseg. Yog tias nws ntau dua, txoj cai xav tias lub pob tau raug nias rau lub sijhawm ntawd thiab teb. Neat!
Khiav koj cov cai thiab xyuas nws ua haujlwm. Yog tias koj muaj qhov yuam kev, txheeb xyuas koj cov cai!
Tam sim no, cia saib ib qho piv txwv piv txwv.
Kauj Ruam 6: Ua Cov Ntawv Qhia
Khawm yog qhov nthuav, vim tias muaj ntau txoj hauv kev nrog lawv! Hauv qhov piv txwv no, peb yuav ua cov ntawv qhia zaub mov. Cia peb hais tias koj tau tsim lub cuab yeej zoo heev no, thiab xav tau cov neeg siv tuaj yeem hloov pauv xaiv kom tig qee yam rau lossis tawm, lossis teeb tus nqi tshwj xeeb rau kev teeb tsa. Qhov peb tsim lub pob no tuaj yeem ua li ntawd!
Yog li, rau txoj haujlwm no peb xav tau:
- Peb cov nyees khawm
- Peb tus tiv thaiv teeb tsa rau 10kΩ
Peb twb muaj ib qho ntawm cov no, peb tsuas xav tau ob qho ntxiv. Yog li ntxiv cov ntawd rau pawg thawj coj saib. Kev xaim hluav taws xob yog qhov nyuaj me ntsis, tab sis tsuas yog vim kuv xav ua kom nws nruj me ntsis. Koj tuaj yeem ua raws tus qauv qub rau thawj lub pob, lossis ua raws daim duab saum toj no.
Peb lub nyees khawm yog cov ntawv qhia zaub mov qhib/xaiv tom ntej, kev hloov pauv (xws li hauv, hloov kho qhov teeb tsa), thiab txuag/kaw cov ntawv qhia zaub mov khawm.
Hlau nws, cia saib lub chaws!
Kauj Ruam 7: Txoj Cai Rhuav - Ntiaj Teb
Ok, qhov no yuav yog kauj ruam ntev, tab sis kuv yuav mus hla txhua ntu ntawm cov cai.
Ua ntej, cia saib lub ntiaj teb hloov pauv xav tau.
// Txhais qhov tsis tu ncua #txhais cov ntawv qhia zaub movButton 2 #define menuSelect 3 #txhais cov ntawv qhia zaub mov Txuag 4 #define debounceTimeout 50 // Txhais cov kev hloov pauv hauv menuButtonPreviousState = LOW; int menuSelectPreviousState = QIB; int menuSavePreviousState = QIB; ntev int lastDebounceTime; // Ntawv qhia zaub mov xaiv char * menuOptions = {"Txheeb Temp", "Check Light"}; bool featureSetting = {tsis tseeb, tsis tseeb}; bool menuMode = tsis tseeb; bool menuNeedsPrint = tsis tseeb; int kev xaivSelected = 0;
Peb ntu no zoo ib yam li qhov peb tau pom ua ntej. Hauv thawj zaug, Kuv tau piav qhia peb lub khawm thiab sijhawm tas sijhawm. Rau ib feem ntawm txoj haujlwm no, Kuv tau teeb tsa nws mus rau 50ms yog li nws siv sijhawm txhob txwm tshaj tawm xovxwm kom nws ua haujlwm.
Qhov thib ob thaiv yog txhua qhov sib txawv. Peb yuav tsum tau taug qab ntawm khawmPreviousState, thiab peb yuav tsum taug qab qhov kawgDebounceTime. Cov no yog txhua yam kev hloov pauv, tab sis qhov kawg yog hom ntev vim tias kuv xav tias peb xav tau qhov chaw hauv nco.
Cov ntawv qhia zaub mov xaiv thaiv muaj ob peb yam tshiab. Ua ntej tshaj, tus char * (yog, uas yog lub hnub qub txhob txwm tshaj tawm), uas yog tus cwj pwm/txoj hlua tsis sib xws. Nws yog tus taw qhia rau kev khaws cia zoo li qub hauv kev nco. Koj tsis tuaj yeem hloov nws (zoo li koj tuaj yeem ua hauv Python, piv txwv). Qhov char *menuOptions kab tsim kab ntawm kab ntawv. Koj tuaj yeem ntxiv ntau cov ntawv qhia zaub mov raws li koj nyiam.
Qhov bool featureSetting nce mus nce los tsuas yog cov kab ntawm qhov muaj txiaj ntsig uas sawv cev rau txhua qhov khoom noj khoom haus. Yog, koj tuaj yeem khaws txhua yam uas koj nyiam, tsuas yog hloov hom sib txawv (lawv txhua tus yuav tsum yog tib hom). Tam sim no, tej zaum yuav muaj txoj hauv kev zoo los tswj qhov no, zoo li phau ntawv txhais lus lossis tuples, tab sis qhov no yooj yim rau daim ntawv thov no. Kuv yuav zaum tsim ib qho tom kawg hauv daim ntawv thov xa mus.
Kuv tau khaws txoj hauv kev ntawm menuMode, yog li yog tias kuv xav tau lwm yam ntawm kuv cov zaub kuv tuaj yeem ua qhov ntawd. Tsis tas li, yog tias kuv muaj lub logic sensor kuv tuaj yeem ncua qhov ntawd thaum lub tshuab ua haujlwm, tsuas yog qee yam tsis sib haum. Kuv muaj menuNeedsPrint hloov pauv vim kuv xav sau cov ntawv qhia zaub mov ntawm lub sijhawm tshwj xeeb, tsis yog txhua lub sijhawm. Thaum kawg, Kuv muaj qhov xaivSelected variable, yog li kuv tuaj yeem taug qab cov kev xaiv uas tau xaiv raws li kuv nkag mus rau hauv ntau qhov chaw.
Cia peb saib cov txheej txheem tom ntej.
Kauj Ruam 8: Txoj Cai Rhuav - Teeb thiab Kev Ua Haujlwm Tshwj Xeeb
Kev teeb tsa () ua haujlwm yooj yim txaus, tsuas yog peb qhov kev tshaj tawm:
teeb tsa tsis muaj dab tsi () {pinMode (menuSelect, INPUT); pinMode (menuSave, INPUT); pinMode (menuSelect, INPUT); Serial.begin (9600); }
Tom ntej no yog peb txoj haujlwm tshwj xeeb. Cia saib thawj ob, tom qab ntawv kawg sib cais.
Peb xav tau ob txoj haujlwm uas xa qee cov ntaub ntawv. Qhov laj thawj yog, peb xav kom ntseeg tau tias qhov no yog tib neeg nyeem tau. Nws tseem yuav pab daws qhov teeb meem cov cai yog tias peb muaj teeb meem. Txoj Cai:
// Ua haujlwm kom rov qab xaiv qhov kev xaiv tam sim no *ReturnOptionSelected () {char *menuOption = menuOptions [optionSelected]; // Rov qab xaiv Xaiv rov qab menuOption; } // Muaj nuj nqi kom rov qab xwm txheej ntawm kev xaiv tam sim no char *ReturnOptionStatus () {bool optionSetting = featureSetting [optionSelected]; char *optionSettingVal; yog (optionSetting == tsis tseeb) {optionSettingVal = "Cuav"; } lwm {optionSettingVal = "Muaj tseeb"; } // Rov qab xaivSetting rov xaiv optionSettingVal; }
Char *ReturnOptionSelected () muaj nuj nqi tshawb xyuas qhov kev xaiv uas tau xaiv (yog tias koj pom saum toj no, peb teeb tsa qhov sib txawv kom taug qab qhov ntawd), thiab rub txoj hlua los ntawm kab ntawv uas peb tau tsim ua ntej. Nws mam li rov qab los ua hom char. Peb paub qhov no vim tias txoj haujlwm qhia pom hom rov qab los.
Qhov ua haujlwm thib ob, char *ReturnOptionStatus () nyeem cov xwm txheej ntawm qhov kev xaiv uas tau txais kev cawmdim hauv kab lus thiab rov ua txoj hlua ncaj uas sawv cev rau tus nqi. Piv txwv li, yog tias qhov chaw uas peb tau khaws cia tsis raug, kuv yuav rov qab "Cuav". Qhov no yog vim peb qhia tus neeg siv qhov sib txawv no thiab nws zoo dua kom khaws txhua qhov kev xav no ua ke. Kuv tuaj yeem ua nws tom qab, tab sis nws ua rau nkag siab ntau los ua nws ntawm no.
// Muaj nuj nqi toggle tam sim no optionbool ToggleOptionSelected () {featureSetting [optionSelected] =! FeatureSetting [optionSelected]; rov muaj tseeb; }
Kev ua haujlwm bool ToggleOptionSelected () yog txoj haujlwm yooj yim los hloov tus nqi ntawm qhov chaw peb tau xaiv hauv cov ntawv qhia zaub mov. Nws tsuas yog ntxeev tus nqi. Yog tias koj muaj txoj kev xaiv nyuaj dua, qhov no yuav txawv heev. Kuv rov qab muaj tseeb hauv txoj haujlwm no, vim tias kuv hu rov qab (hu tom qab hauv cov cai uas ua rau lub luag haujlwm no) cia siab tias qhov tseeb/tsis raug teb. Kuv 100% paub tseeb tias qhov no yuav ua haujlwm, yog li kuv tsis suav rau nws tsis ua haujlwm, tab sis kuv yuav nyob hauv daim ntawv thov xa mus (tsuas yog hauv rooj plaub).
Kauj Ruam 9: Lub Loop…
Lub voj () kev ua haujlwm yog qhov ntev txaus, yog li peb yuav ua nws ib feem. Koj tuaj yeem xav txhua yam hauv qab zes nyob hauv txoj haujlwm no:
void voj () {
// Ua haujlwm ntawm no <-----}
Ok, peb pom cov khoom no ua ntej:
// Nyeem cov nyees khawm int menuButtonPressed = digitalRead (menuButton); int menuSelectPressed = digitalRead (menuSelect); int menuSavePressed = digitalRead (menuSave); // Tau txais lub sijhawm tam sim no ntev int currentTime = millis (); yog tias (menuButtonPressed == LOW && menuSelectPressed == LOW && menuSavePressed == LOW) {// Rov pib suav lub sijhawm thaum khawm tsis nias lastDebounceTime = currentTime; menuButtonPreviousState = QIB; menuSelectPreviousState = QIB; menuSavePreviousState = QIB; }
Txhua yam kuv yuav tsum tau ua ntawm no yog ntxiv rau hauv peb qhov digitalRead () hu, thiab paub tseeb tias kuv suav rau qhov tseeb tias yog tias txhua lub khawm tau qis, peb yuav tsum rov pib lub sijhawm (lastDebounceTime = currentTime) thiab teeb tsa txhua lub xeev dhau los kom qis. Kuv tseem khaws millis () hauv lub sijhawm tam sim no.
Tshooj tom ntej zes hauv kab
yog (((tam sim noTime - lastDebounceTime)> debounceTimeout)) {
// Ua haujlwm ntawm no <----}
Muaj peb ntu. Yog lawm, kuv tuaj yeem txav lawv mus rau hauv lawv tus kheej lub luag haujlwm, tab sis rau qhov yooj yim kuv tau khaws peb lub ntsiab lus tseem ceeb algorithms nyob ntawm no.
yog ((menuButtonPressed == HIGH) && (menuButtonPreviousState == LOW)) {yog (menuMode == tsis tseeb) {menuMode = tseeb; // Qhia rau tus neeg siv paub Serial.println ("Cov ntawv qhia zaub mov tau ua haujlwm"); } lwm yog (menuMode == tseeb && optionSelected = 1) {// Rov pib dua qhov kev xaiv optionSelected = 0; } // Luam tawm cov ntawv qhia zaub mov menuNeedsPrint = muaj tseeb; // Toggle khawm ua ntej. lub xeev tsuas yog tso saib cov ntawv qhia zaub mov // yog tias lub pob raug tso tawm thiab nias dua menuButtonPreviousState = menuButtonPressed; // Yuav yog HIGH}
Thawj qhov no ua haujlwm thaum menuButtonPressed yog HIGH, lossis thaum lub tshuab raj khawm raug nias. Nws kuj tseem txheeb xyuas kom paub tseeb tias lub xeev dhau los yog LOW, yog li lub pob yuav tsum tau tso tawm ua ntej nws tau nyem dua, uas txwv qhov kev zov me nyuam los ntawm kev ua haujlwm tas li tas li.
Nws mam li txheeb xyuas tias yog tias cov ntawv qhia zaub mov tsis ua haujlwm, nws ua rau nws. Nws yuav luam tawm thawj qhov kev xaiv uas tau xaiv (uas yog thawj qhov khoom hauv cov ntawv qhia zaub mov xaiv kab lus los ntawm lub neej ntawd. Yog tias koj nias lub pob thib ob lossis thib peb (thiab lwm yam) lub sijhawm, koj yuav tau txais qhov kev xaiv tom ntej hauv cov npe. qhov no thaum nws mus txog qhov kawg, nws yuav rov mus pib.
Tshooj me me kawg (// Luam tawm cov ntawv qhia zaub mov) pom tseeb luam tawm cov ntawv qhia zaub mov, tab sis nws kuj teeb tsa lub xeev dhau los rau HIGH yog li cov haujlwm zoo ib yam yuav tsis tig (saib kuv cov ntawv sau saum toj no hais txog kev txheeb xyuas yog tias lub pob tau qis dua yav dhau los).
// menuSelect raug nias, muab logicif ((menuSelectPressed == HIGH) && (menuSelectPreviousState == LOW)) {yog (menuMode) {// Hloov qhov kev xaiv uas tau xaiv // Tam sim no, qhov no tsuas yog qhov tseeb/cuav // tab sis yuav yog txhua yam bool toggle = ToggleOptionSelected (); yog (toggle) {menuNeedsPrint = muaj tseeb; } lwm {Serial.println ("Muaj qee yam tsis raug. Thov sim dua"); }} // Toggle xeev tsuas yog toggle yog tso tawm thiab nias dua menuSelectPreviousState = menuSelectPressed; }
Qhov me ntsis ntawm txoj cai tswj hwm cov ntawv qhia zaub mov Xaiv khawm hauv tib txoj kev, tshwj tsis yog lub sijhawm no peb tsuas yog tua ToggleOptionSelected () ua haujlwm. Raws li kuv tau hais ua ntej, koj tuaj yeem hloov txoj haujlwm no kom nws ua tau ntau dua, tab sis qhov ntawd yog txhua yam kuv xav kom nws ua.
Qhov tseem ceeb kom nco ntsoov yog toggle sib txawv, uas taug qab qhov ua tiav ntawm kev hu rov qab thiab luam tawm cov ntawv qhia zaub mov yog tias muaj tseeb. Yog tias nws tsis rov qab los tsis muaj dab tsi, nws yuav sau cov lus yuam kev. Nov yog qhov uas koj tuaj yeem siv koj li kev hu rov qab los ua lwm yam.
yog tias ((menuSavePressed == HIGH) && (menuSavePreviousState == LOW)) {// Tawm ntawm cov ntawv qhia zaub mov // Ntawm no koj tuaj yeem ua ib qho kev kho kom raug // lossis txuag rau EEPROM menuMode = cuav; Serial.println ("Ntawv qhia zaub mov tawm"); // Toggle lub xeev yog li ntawv qhia zaub mov tsuas yog tawm ib zaug menuSavePreviousState = menuSavePressed; }}
Txoj haujlwm no ua haujlwm cov ntawv qhia zaub movSave khawm, uas tsuas yog tawm ntawm cov ntawv qhia zaub mov. Nov yog qhov uas koj tuaj yeem tshem tawm lossis khaws cov kev xaiv, tej zaum ua qee qhov kev tu lossis txuag rau EEPROM. Kuv tsuas yog luam tawm "Ntawv qhia zaub mov tawm" thiab teeb tsa lub xeev khawm kom HIGH yog li nws tsis tig.
yog (menuMode && menuNeedsPrint) {// Peb tau luam tawm cov ntawv qhia zaub mov, yog li tshwj tsis yog qee yam // tshwm sim, tsis tas yuav luam nws dua menuNeedsPrint = cuav; char *optionActive = ReturnOptionSelected (); char *optionStatus = ReturnOptionStatus (); Serial.print ("Xaiv:"); Serial.print (optionActive); Serial.print (":"); Serial.print (optionStatus); Serial.println (); }
Qhov no yog menuPrint algorithm, uas tsuas yog tua hluav taws thaum cov ntawv qhia ua haujlwm thiab thaum cov ntawv qhia zaub mov NeedsPrint sib txawv tau teeb tsa kom raug.
Qhov no tuaj yeem txav mus rau nws tus kheej txoj haujlwm, tab sis rau qhov yooj yim..!
Zoo, yog nws! Saib cov kauj ruam tom ntej rau tag nrho cov cai thaiv.
Kauj Ruam 10: Kawg Txoj Cai Thaiv
// Txheeb cais
#define menuButton 2 #define menuSelect 3 #define menuSave 4 #define debounceTimeout 50 int menuButtonPreviousState = LOW; int menuSelectPreviousState = QIB; int menuSavePreviousState = QIB; // Txhais qhov sib txawv ntev int lastDebounceTime; bool lightSensor = muaj tseeb; bool tempSensor = muaj tseeb; // Ntawv qhia zaub mov xaiv char * menuOptions = {"Txheeb Temp", "Check Light"}; bool featureSetting = {tsis tseeb, tsis tseeb}; bool menuMode = tsis tseeb; bool menuNeedsPrint = tsis tseeb; int kev xaivSelected = 0; // Teeb muaj nuj nqi
teeb tsa tsis muaj dab tsi () {pinMode (menuSelect, INPUT); pinMode (menuSave, INPUT); pinMode (menuSelect, INPUT); Serial.begin (9600); }
// Muaj nuj nqi kom rov xaiv qhov kev xaiv tam sim no char *ReturnOptionSelected () {char *menuOption = menuOptions [optionSelected]; // Rov qab xaiv Xaiv rov qab menuOption; } // Muaj nuj nqi kom rov qab xwm txheej ntawm kev xaiv tam sim no char *ReturnOptionStatus () {bool optionSetting = featureSetting [optionSelected]; char *optionSettingVal; yog (optionSetting == tsis tseeb) {optionSettingVal = "Cuav"; } lwm {optionSettingVal = "Muaj tseeb"; } // Rov qab xaivSetting rov xaiv optionSettingVal; } // Muaj nuj nqi toggle kev xaiv tam sim no bool ToggleOptionSelected () {featureSetting [optionSelected] =! FeatureSetting [optionSelected]; rov muaj tseeb; } // Lub ntsiab voj
void loop () {// Nyeem cov nyees khawm int menuButtonPressed = digitalRead (menuButton); int menuSelectPressed = digitalRead (menuSelect); int menuSavePressed = digitalRead (menuSave); // Tau txais lub sijhawm tam sim no ntev int currentTime = millis (); yog tias (menuButtonPressed == LOW && menuSelectPressed == LOW && menuSavePressed == LOW) {// Rov pib suav lub sijhawm thaum khawm tsis nias lastDebounceTime = currentTime; menuButtonPreviousState = QIB; menuSelectPreviousState = QIB; menuSavePreviousState = QIB; } yog (((tam sim noTime - lastDebounceTime)> debounceTimeout)) {// Yog tias lub sijhawm dhau mus txog, khawm nias!
// menuButton raug nias, muab cov laj thawj
// Tsuas yog hluav taws thaum lub pob tau tso tawm ua ntej yog ((menuButtonPressed == HIGH) && (menuButtonPreviousState == LOW)) {yog (menuMode == cuav) {menuMode = tseeb; // Qhia rau tus neeg siv paub Serial.println ("Cov ntawv qhia zaub mov tau ua haujlwm"); } lwm yog (menuMode == tseeb && optionSelected = 1) {// Rov pib dua qhov kev xaiv optionSelected = 0; } // Luam tawm cov ntawv qhia zaub mov menuNeedsPrint = muaj tseeb; // Toggle khawm ua ntej. lub xeev tsuas yog tso saib cov ntawv qhia zaub mov // yog tias lub pob raug tso tawm thiab nias dua menuButtonPreviousState = menuButtonPressed; // Yuav yog HIGH} // menuSelect raug nias, muab cov laj thawj yog ((menuSelectPressed == HIGH) && (menuSelectPreviousState == LOW)) {yog (menuMode) {// Hloov qhov kev xaiv uas tau xaiv // Tam sim no, qhov no yog tsuas yog qhov tseeb/tsis tseeb // tab sis tuaj yeem yog txhua yam bool toggle = ToggleOptionSelected (); yog (toggle) {menuNeedsPrint = muaj tseeb; } lwm {Serial.print ("Muaj qee yam tsis raug. Thov sim dua"); }} // Toggle xeev tsuas yog toggle yog tso tawm thiab nias dua menuSelectPreviousState = menuSelectPressed; } yog ((menuSavePressed == HIGH) && (menuSavePreviousState == LOW)) {// Tawm ntawm cov ntawv qhia zaub mov // Ntawm no koj tuaj yeem ua ib qho tidying li // lossis txuag rau EEPROM menuMode = cuav; Serial.println ("Ntawv qhia zaub mov tawm"); // Toggle lub xeev yog li ntawv qhia zaub mov tsuas yog tawm ib zaug menuSavePreviousState = menuSavePressed; }} // Luam tawm cov ntawv qhia zaub mov tam sim no ua haujlwm, tab sis tsuas yog luam nws ib zaug yog (menuMode && menuNeedsPrint) {// Peb tau luam tawm cov ntawv qhia zaub mov, yog li tshwj tsis yog qee yam // tshwm sim, tsis tas yuav luam nws dua menuNeedsPrint = cuav; char *optionActive = ReturnOptionSelected (); char *optionStatus = ReturnOptionStatus (); Serial.print ("Xaiv:"); Serial.print (optionActive); Serial.print (":"); Serial.print (optionStatus); Serial.println (); }}}
Lub Circuit Court muaj nyob ntawm Tinkercad qhov chaw. Kuv tau kos lub voj voog hauv qab no rau koj pom, ib yam nkaus!
Raws li ib txwm, yog tias koj muaj lus nug lossis teeb meem, thov qhia rau kuv paub!
Pom zoo:
Yuav Ua Li Cas Vaum Thiab Kub Tiag Tiag Cov Ntaub Ntawv Teev Npe Nrog Arduino UNO thiab SD-Card - DHT11 Cov ntaub ntawv-logger Simulation hauv Proteus: 5 Cov Kauj Ruam
Yuav Ua Li Cas Vaum Thiab Kub Tiag Tiag Cov Ntaub Ntawv Teev Npe Nrog Arduino UNO thiab SD-Card | DHT11 Cov ntaub ntawv-logger Simulation hauv Proteus: Taw qhia: nyob zoo, qhov no yog Liono Maker, ntawm no yog YouTube txuas. Peb tab tom tsim txoj haujlwm muaj tswv yim nrog Arduino thiab ua haujlwm ntawm cov kab ke. Cov ntaub ntawv-Logger: Cov ntaub ntawv logger (tseem cov ntaub ntawv-logger lossis cov ntaub ntawv kaw) yog cov cuab yeej siv hluav taws xob uas sau cov ntaub ntawv dhau sijhawm
Loj hlob Zaub Zaub Ntxiv Hauv Qhov Chaw Tsawg Los Yog Loj hlob Zaub Zaub Hauv Chaw, (Ntau lossis Tsawg): 10 Kauj Ruam
Loj Hlob Ntau Cov Zaub Zaub Hauv Tsawg Chaw lossis … Loj hlob Zaub Zaub Hauv Chaw, (Ntau lossis Tsawg).: Qhov no yog kev tshaj lij tshaj lij rau Kev Loj Hlob Tshaj Ntiaj Teb, Kev Tsim Khoom Sib Tw, xa los ntawm Cov Lus Qhia. Kuv tsis tuaj yeem muaj kev zoo siab dua los tsim rau thaj chaw cog qoob loo thiab tshaj tawm kuv thawj Cov Lus Qhia. Yuav pib, kev sib tw nug peb kom
Kev Tuaj Koom Nrog Nrog Khaws Cov Ntaub Ntawv hauv Google Daim Ntawv Qhia Siv RFID thiab Arduino Ethernet Shield: 6 Cov Kauj Ruam
Kev Tuaj Koom Nrog Nrog Khaws Cov Ntaub Ntawv hauv Google Daim Ntawv Qhia Siv RFID thiab Arduino Ethernet Shield: Nyob Zoo Cov Neeg, Ntawm no peb los nrog txoj haujlwm zoo siab heev thiab yog li yuav xa cov ntaub ntawv rfid rau google daim ntawv qhia siv Arduino li cas. Hauv ntej peb yuav ua qhov kev tuaj koom raws rfid nyeem ntawv uas yuav txuag cov ntaub ntawv tuaj koom hauv lub sijhawm tiag tiag rau goog
Ntse Suab Nkauj hauv Chav Dej thiab Da Dej Nrog Raspberry Pi - Sib Koom Ua Ke Hauv Chav, Tswb, Khawm Tswj thiab Kev Siv Tsev Hauv Tsev: 7 Kauj Ruam
Ntse Suab Nkauj hauv chav pw thiab Da Dej Nrog Raspberry Pi - Sib Koom Ua Ke Hauv Chav, Tswb, Khawm Tswj thiab Kev Siv Tsev Hauv Tsev: Niaj hnub no peb xav muab ob qho piv txwv txog yuav ua li cas koj tuaj yeem siv Raspberry Pi nrog peb Max2Play software rau hauv tsev automation: hauv chav dej thiab chav pw . Ob txoj haujlwm zoo ib yam nyob hauv cov suab paj nruag siab ncaj los ntawm ntau qhov chaw tuaj yeem rub tawm los
Arduino Ntawv Qhia zaub mov ntawm Nokia 5110 Lcd Siv Lub Tshuab Rotary Encoder: 6 Cov Kauj Ruam (nrog Duab)
Arduino Cov Ntawv Qhia ntawm Nokia 5110 Lcd Siv Lub Tshuab Rotary Encoder: Nyob zoo cov phooj ywg zoo siab txais tos rau lwm qhov kev qhia! Hauv daim vis dis aus no peb yuav kawm paub tsim peb cov ntawv qhia zaub mov li cas rau Nokia 5110 LCD zaub uas nrov, txhawm rau ua kom peb cov phiaj xwm siv cov phooj ywg zoo thiab muaj peev xwm ntau dua. Cia ’ s pib! Qhov no yog txoj haujlwm