Cov txheej txheem:

Qhov Ntsuas Kub Kub RGB (nrog XinaBox): 5 Kauj Ruam (nrog Duab)
Qhov Ntsuas Kub Kub RGB (nrog XinaBox): 5 Kauj Ruam (nrog Duab)

Video: Qhov Ntsuas Kub Kub RGB (nrog XinaBox): 5 Kauj Ruam (nrog Duab)

Video: Qhov Ntsuas Kub Kub RGB (nrog XinaBox): 5 Kauj Ruam (nrog Duab)
Video: Kawm txog ntawm xub thawj thiab tom qab paj quaj yog siv li cas? || Qhia looj phaj EP4 2024, Hlis ntuj nqeg
Anonim
Qhov Ntsuas Kub Kub RGB (nrog XinaBox)
Qhov Ntsuas Kub Kub RGB (nrog XinaBox)

Nov yog qhov tseeb kuv thawj Cov Ntawv Qhia Qhia, yog li kuv yuav lees tias kuv siv lub sijhawm no tam sim no los sim nws. Tau txais kev xav ntawm yuav ua li cas lub platform ua haujlwm, tag nrho cov neeg siv tau ntsib ib sab ntawm nws. Tab sis thaum kuv ua qhov ntawd, Kuv xav tias kuv tseem tuaj yeem siv sijhawm los qhia txog txoj haujlwm yooj yim uas kuv tau ua haujlwm niaj hnub no (siv cov khoom lag luam los ntawm XinaBox, uas los ntawm txoj kev, tau hais tawm ua "X-in-a- Lub thawv ").

Hauv qhov yooj yim 5-qib qhia, kuv yuav hais txog cov ncauj lus hauv qab no:

  • Cov khoom xav tau
  • Txuas qhov sib txawv xChips ua ke.
  • Teeb tsa Arduino IDE ib puag ncig.
  • Sau cov cai
  • Thiab thaum kawg, sim lub tswv yim tawm

Qhov kuv yuav tsis koom nrog hauv cov lus qhia no:

  • Ntau npaum li kuv nyiam dhia hauv kev piav qhia txhua tus ntawm xChips tuaj yeem ua dab tsi thiab koj tuaj yeem siv lawv li cas los ua qee yam kev ua haujlwm, uas yuav tsis yog lub hom phiaj ntawm cov lus qhia no. Kuv npaj tshaj tawm lwm Cov Lus Qhia rau yav tom ntej uas yuav dhia mus rau txhua qhov sib txawv xChips uas muaj los ntawm XinaBox cov khoom lag luam.
  • Kuv yuav tsis nkag mus rau qhov pib ntawm Arduino code raws li kuv xav tias koj twb muaj qee qib kev paub nrog siv Arduino IDE ntxiv rau kev nkag siab theem pib ntawm C/C ++ programming.

Kauj Ruam 1: Yam Koj Xav Tau…

Yam Koj Xav Tau …
Yam Koj Xav Tau …
Yam Koj Xav Tau …
Yam Koj Xav Tau …
Yam Koj Xav Tau …
Yam Koj Xav Tau …

Txuj ci, feem ntau cov khoom qhia yooj yim feem ntau pib nrog "Nyob Zoo Ntiaj Teb!" piv txwv, lossis txawm tias "Blink" piv txwv, uas koj yuav twb paub zoo heev txij li koj tau ua haujlwm nrog Arduino lossis Raspberry Pi ntawm qee kis. Tab sis kuv tsis xav pib nrog qhov ntawd vim txhua leej txhua tus twb tau ua ib yam nkaus, uas ua rau nws txaus siab me ntsis tiag tiag.

Hloov chaw, Kuv xav pib nrog lub tswv yim ua haujlwm. Ib yam uas yog ob qho yooj yim txaus thiab ua kom haum rau hauv cov phiaj xwm txoj haujlwm nyuaj dua yog tias koj xav tau.

Nov yog cov khoom uas peb yuav xav tau (xa mus rau cov duab muab rau ntu no ntawm Cov Lus Qhia):

  1. IP02 - Advanced USB Programming Interface
  2. CC03 - Caj npab Cortex M0+ Core
  3. SW02 - VOC thiab Huab Cua Huab Cua (uas siv BME680 sensor los ntawm BOSCH)
  4. xBUS cov khoom sib txuas - kom pab tau I2C kev sib txuas lus ntawm xChips sib txawv (x2)
  5. xPDI txuas - kom pab tau lub cajmeem thiab debugging (x1)

Kauj Ruam 2: Txuas Cov Ntawv

Txuas Cov Khoom
Txuas Cov Khoom
Txuas Cov Khoom
Txuas Cov Khoom
Txuas Cov Khoom
Txuas Cov Khoom

Txhawm rau txuas txhua daim ua ke, peb yuav xub pib nrog 1 daim ntawm xBUS txuas thiab xPDI txuas.

Ua raws li cov duab uas kuv tau muab, pom qhov kev taw qhia ntawm xChips thiab qhov txuas yuav mus qhov twg.

Nruab nrab ntawm IP02 & CC03 xChips, nws yooj yim heev los txheeb xyuas cov ntsiab lus sib txuas.

Rau CC03, nws yuav yog sab qab teb. Rau IP02, nws yuav yog sab qaum teb ntawm xChip.

Thaum qhov ntawd ua tiav, peb yuav ntxiv lwm qhov xBUS txuas rau sab hnub poob ntawm CC03 xChip.

Ua tiav?

Tam sim no, tsuas yog txuas SW02 xChip mus rau sab hnub poob ntawm CC03.

Ua ntej peb ntxig IP02 rau peb lub khoos phis tawj, xyuas kom meej tias cov kev xaiv hauv qab no tau xaiv rau ob qhov hloov pauv:

  • B tau xaiv (sab laug hloov)
  • DCE raug xaiv (txoj cai hloov)

Thaum kawg, tam sim no peb tau npaj los ntxig IP02 rau hauv peb lub laptop thiab pib teeb tsa Arduino IDE.

Kauj Ruam 3: Teeb Arduino IDE

Teeb tsa Arduino IDE
Teeb tsa Arduino IDE
Teeb tsa Arduino IDE
Teeb tsa Arduino IDE

Ib zaug ntxiv, hauv cov lus qhia no, Kuv tau ua qhov kev xav tias koj twb paub zoo txog Arduino IDE ib puag ncig nrog rau yuav ua li cas tswj cov tsev qiv ntawv nyob hauv ib puag ncig kev txhim kho.

Rau lub hom phiaj ntawm txoj haujlwm no, peb yuav xav tau ob lub tsev qiv ntawv tseem ceeb:

  • arduino-CORE-https://github.com/xinabox/arduino-CORE
  • SW02 lub tsev qiv ntawv -

Rub tawm ob lub tsev qiv ntawv mus rau qhov chaw nyob hauv koj lub desktop.

Tom ntej no, tso koj li Arduino IDE.

Los ntawm cov ntawv qhia zaub mov tseem ceeb, xaiv "Sketch"> "Include Library"> "Add. ZIP Library …"

Rov ua cov txheej txheem qub rau ob lub tsev qiv ntawv cov ntaub ntawv.

Tom ntej no, peb yuav tsum xaiv qhov cuam tshuam "Board" nrog rau "Port". (Daim ntawv ceeb toom tias kuv tseem tau hais qhia qhov kev xaiv tsim nyog siv lub thawv txiv kab ntxwv.

  • Pawg thawj coj: "Arduino/Genuino Zero (Native USB Port)"
  • Chaw nres nkoj: "COMXX" (qhov no yuav tsum yog raws li COM chaw nres nkoj uas tau cuam tshuam los ntawm koj lub tshuab. Kuv siv COM31)

Nyob zoo! Kuv paub koj tau mob siab rau dhia mus rau tus lej, yog li hauv qib tom ntej, qhov ntawd yog qhov peb yuav tsom mus rau.

Kauj ruam 4: Sijhawm rau Code

Hauv ntu no, Kuv yuav pib los ntawm kev sib qhia cov lej ntawm qhov ua tiav txoj haujlwm. Thiab thaum kawg, kuv yuav tshaj tawm tag nrho cov peev txheej, ua kom yooj yim rau koj kom yooj yim luam thiab muab cov lej tso rau hauv koj li Arduino IDE cov ntaub ntawv.

Cov Ntaub Ntawv Header:

#include /* Nov yog lub tsev qiv ntawv rau XinaBox Core Functions. */

#suav nrog /* Nov yog lub tsev qiv ntawv rau VOC & Huab Cua Sensor xChip. */

Txhais qee qhov tsis tu ncua rau kev tswj hwm RGB Led Teeb liab:

#define redLedPin A4

#define ntsuabLedPin 8 #define blueLedPin 9

Tom ntej no, peb yuav tsum tshaj tawm txoj haujlwm ua qauv rau dhau qhov RGB qhov tseem ceeb

void setRGBColor (int redValue, int greenValue, int blueValue);

Tshaj tawm cov khoom SW02:

xSW02 SW02;

Txoj kev teeb tsa () txheej txheem:

void teeb tsa () {

// Pib I2C Kev Sib Txuas Hlau.begin (); // Pib SW02 Sensor SW02.begin (); // Ncua rau lub ntsuas kom ua haujlwm qeeb (5000); }

Tam sim no rau lub ntsiab voj ():

void voj () {

ntab tempC; }

Tom ntej no, peb yuav tsum tau pov npav siv cov khoom SW02 uas peb tau tsim ua ntej hauv txoj haujlwm kom pib peb kev sib txuas lus nrog lub nti sensor:

// Nyeem thiab xam cov ntaub ntawv los ntawm SW02 sensorSW02.poll ();

Tam sim no, peb tab tom nyeem ntawv kom tau txais lub ntsuas qhov ntsuas kub

tempC = SW02.getTempC ();

Thaum peb tau nyeem, qhov kawg uas peb tab tom yuav ua yog siv ib qho ntawm yog tias … lwm yam … tswj cov lus los txiav txim siab qhov ntsuas kub, thiab tom qab ntawd hu rau setRGBColor () ua haujlwm

// Koj tuaj yeem hloov kho qhov kub thiab txias raws li koj qhov huab cua. Rau kuv, Kuv nyob hauv Singapore, // uas yog huab cua sov txhua xyoo puag ncig, thiab qhov kub thiab txias tuaj yeem nqaim ntawm no. yog (tempC> = 20 && tempC = 25 && tempC = 30 && tempC = 32 && tempC = 35) {setRGBColor (255, 0, 0); }

Nco tseg: Yog tias koj xav paub dab tsi cuam tshuam txog RGB qhov tseem ceeb rau cov xim tshwj xeeb, Kuv xav kom koj ua google tshawb rau "RGB xim qhov tseem ceeb". Muaj ntau qhov chaw muaj nyob qhov twg koj tuaj yeem siv tus xaiv xim xaiv cov xim uas koj xav tau

// Yog tias koj nyiam, thiab nws yog nyob ntawm yeem, koj tuaj yeem ntxiv qhov ncua sijhawm ntawm kev pov npav rau lub ntsuas qhov nyeem ntawv.

ncua (DELAY_TIME);

Koj tuaj yeem tshaj tawm qhov DELAY_TIME tas li thaum pib ntawm txoj haujlwm, txoj kev ntawd, koj tsuas yog yuav tsum hloov kho nws tus nqi ib zaug ntau dua li ntau qhov chaw thoob plaws hauv koj qhov program. Thaum kawg, peb xav tau txoj haujlwm los tswj peb RGB LED:

void setRGBColor (int redValue, int greenValue, int blueValue) {

analogWrite (redLedPin, redValue); analogWrite (ntsuabLedPin, ntsuabValue); analogWrite (blueLedPin, blueValue); }

Qhov Kev Kawm Kawg

#suav nrog

#suav nrog #define redLedPin A4 #define ntsuabLedPin 8 #define blueLedPin 9 tsis muaj teeb meem setRGBColor (int redValue, int greenValue, int blueValue); const int DELAY_TIME = 1000; xSW02 SW02; teeb tsa tsis muaj dab tsi () {// Pib I2C Kev Sib Txuas Hlau.begin (); // Pib SW02 Sensor SW02.begin (); // Ncua rau lub ntsuas kom ua haujlwm qeeb (5000); } void loop () {// Tsim kom muaj qhov sib txawv los khaws cov ntaub ntawv nyeem los ntawm SW02 ntab tempC; tempC = 0; // Nyeem thiab xam cov ntaub ntawv los ntawm SW02 sensor SW02.poll (); // Thov SW02 kom tau txais qhov ntsuas kub thiab khaws cia hauv // ntsuas kub sib txawv tempC = SW02.getTempC (); yog (tempC> = 20 && tempC = 25 && tempC = 30 && tempC = 32 && tempC = 35) {setRGBColor (255, 0, 0); } // Kev ncua me me ntawm lub sensor nyeem qeeb (DELAY_TIME); } void setRGBColor (int redValue, int greenValue, int blueValue) {analogWrite (redLedPin, redValue); analogWrite (ntsuabLedPin, ntsuabValue); analogWrite (blueLedPin, blueValue); }

Tam sim no tias peb txoj haujlwm tau npaj tiav, cia qhov program xChip! Cov txheej txheem Upload yog zoo ib yam li koj yuav tso qhov program rau koj li Arduino boards.

Thaum koj ua tiav, vim li cas ho tsis tshem nws thiab coj nws tawm rau qhov kev sim khiav.

Pom zoo: