Cov txheej txheem:

Fancy LED Hat: 5 Cov Kauj Ruam (nrog Duab)
Fancy LED Hat: 5 Cov Kauj Ruam (nrog Duab)

Video: Fancy LED Hat: 5 Cov Kauj Ruam (nrog Duab)

Video: Fancy LED Hat: 5 Cov Kauj Ruam (nrog Duab)
Video: Dab neeg Niam tais vam ntau 26/5/2017 2024, Kaum ib hlis
Anonim
Image
Image
Fancy LED Lub kaus mom
Fancy LED Lub kaus mom

Kuv ib txwm xav ua qhov project Arduino, tab sis yeej tsis muaj lub tswv yim zoo rau ib qho txog thaum kuv tsev neeg tau raug caw tuaj koom lub kaus mom zoo nkauj. Nrog ob lub lis piam ua lub sijhawm, Kuv xav paub yog tias kuv tuaj yeem npaj ob qho tib si thiab ua kom lub ntsej muag ntxim nyiam LED ua lub ntsej muag lub ntsej muag. Hloov tawm kuv ua tau! Kuv tej zaum tau mus me ntsis hla, tab sis tag nrho cov phiaj xwm raug nqi ib ncig $ 80. Nrog kev sim thiab qee qhov coding koj tuaj yeem ua rau tsawg dua.

Lub hom phiaj nrog lub kaus mom yog cov hauv qab no:

  1. Muaj teeb teeb txav los ntawm lub hauv ntej ntawm lub kaus mom mus rau tom qab, ib lub teeb ntawm txhua sab
  2. Hloov qhov nrawm ntawm lub teeb txoj kev taug kev los ntawm kev qaij ntawm lub kaus mom pem hauv ntej mus rau tom qab
  3. Tso cai rau lub teeb rov qab thaum lub kaus mom khawm tau qaij qis (piv txwv li ua raws lub ntiajteb txawj nqus qhov cuam tshuam ntawm lub teeb)
  4. Hloov xim raws qhov qaij ntawm lub kaus mom sab laug mus rau sab xis
  5. Sense poob siab, thiab tso tawm cov nyhuv tshwj xeeb
  6. Sense tus neeg hnav lub ntsej muag, thiab ua kom pom qhov tshwj xeeb
  7. Kom nws ua tiav hauv lub kaus mom

Kauj Ruam 1: Qhov Yuav Tsum Tau

Qhov Yuav Tsum Tau
Qhov Yuav Tsum Tau
Qhov Yuav Tsum Tau
Qhov Yuav Tsum Tau
Qhov Yuav Tsum Tau
Qhov Yuav Tsum Tau

Kuv siv cov khoom loj hauv qab no (tsis koom nrog Amazon txuas nrog):

  • Teensy LC microcontroller - Kuv tau xaiv qhov no dhau ib txwm Arduino vim nws qhov me me, thiab nws muaj qhov tshwj xeeb txuas rau kev tswj hwm kuv cov LEDs, ntxiv rau lub tsev qiv ntawv muaj zog thiab kev txhawb nqa hauv zej zog.
  • Bosch BNO055 raws qhov ntsuas qhov ntsuas - ua siab ncaj yog ib qho ntawm thawj qhov kuv pom cov ntaub ntawv ntawm. Muaj ntau qhov kev xaiv kim dua, txawm li cas los xij thaum koj xam tawm Bosch nws ua ntau rau koj uas koj yuav tsis tas li yuav tsum tau ua hauv tus lej
  • WS2812 addressable LED sawb - Kuv xaiv qhov ntev 1 meter nrog 144 LEDs ib lub 'meter'. Muaj qhov ntom ntom ntom ntom no pab lub teeb zoo li nws tau txav mus, ntau dua li cov khoom ib tus neeg teeb pom kev ua ntu zus.

Thiab cov khoom me me hauv qab no:

  • Lub kaus mom - txhua lub kaus mom nrog lub kaus mom yuav ua. Nov yog $ 6 lub kaus mom los ntawm lub khw muag khoom hauv zos. Yog tias nws muaj cov nqaws nyob tom qab nws yuav yooj yim dua kom tau cov xov hlau hla. Ua tib zoo saib yog tias lub kaus mom tau txuas nrog vim qhov ntawd tseem yuav ua rau muaj teeb meem ntxiv. Qhov no tau xaws raws saum toj, tab sis hauv qab rub tau yooj yim.
  • 4.7K ohm resistors
  • 3 x AAA roj teeb rooj - siv 3 AAA roj teeb tso tawm qhov hluav taws xob raws nraim hauv cov khoom siv hluav taws xob xav tau, uas ua kom yooj yim dua. AAA haum rau hauv lub kaus mom yooj yim dua AA thiab tseem muaj sijhawm zoo.
  • Cov ntsuas cua me me - Kuv tau siv qee cov hlau uas kuv tau pw ib puag ncig los ntawm qhov project LED yav dhau los.
  • Soldering hlau thiab solder
  • Qee qhov spandex uas haum rau sab hauv xim ntawm lub kaus mom, thiab xov

Pom zoo, tab sis xaiv tau:

  • Cov txuas txuas nrawm rau cov xov tooj roj teeb
  • Pab txhais tes cov cuab yeej, cov khoom no me me heev thiab nyuaj rau solder

Kauj Ruam 2: Hloov Kho Lub Hnab

Hloov Kho Lub Hnab
Hloov Kho Lub Hnab
Hloov Kho Lub Hnab
Hloov Kho Lub Hnab
Hloov Kho Lub Hnab
Hloov Kho Lub Hnab
Hloov Kho Lub Hnab
Hloov Kho Lub Hnab

Koj yuav xav tau ib qho chaw hauv lub kaus mom txhawm rau txhawm rau txuas hluav taws xob, thiab qhov chaw rau roj teeb. Kuv tus poj niam ua haujlwm nrog khaub ncaws tshaj lij, yog li kuv nug nws rau kev qhia thiab pab. Peb tau xaus tsim ob lub hnab ntim nrog spandex. Thawj lub hnab me me rau sab xub ntiag tau taw qhia zoo li lub kaus mom nws tus kheej kom thaum cov khoom siv hluav taws xob tau teeb tsa lub ntsuas qhov ntsuas nyob hauv qhov chaw ncaj ncees, tseem tuaj yeem tshem tawm tau yooj yim yog tias tsim nyog. Lub hnab tshos thib ob rau nraub qaum yog tuav lub roj teeb ntim rau hauv qhov chaw.

Lub hnab ntim tau sown nrog xov uas sib phim xim ntawm lub kaus mom, txhua txoj kab ntev. Nyob ntawm tus qauv ntawm lub kaus mom thiab cov ntaub ntawv nws tau ua los ntawm YMMV nrog cov txheej txheem no.

Peb kuj tau pom lub kaus mom khi rau hauv nws tus kheej ntawm ib sab, thiab nws tau xaws tag rau lub kaus mom hauv qhov chaw ntawd. Peb yuav tsum tshem tawm txoj hlua qub kom thiaj li khiav tau cov LEDs hauv qab pab pawg. Thaum lub sijhawm tsim nws tau tuav nyob rau hauv qhov chaw nrog tus pin, thiab tom qab ntawd xaws nrog cov xov sib txuam thaum ua tiav.

Thaum kawg peb qhib lub qhov nyob rau sab nraum qab ntawm lub kaus mom yog nws tau npog los ntawm pab pawg. Peb tau ntsaws cov hlua hlau uas tuaj nrog LEDs los ntawm txoj hlua khi thiab kab thawj LED hauv kab txaij kom raug rau ntawm txoj hlua. Tom qab ntawd peb qhwv cov LED nyob ib puag ncig lub kaus mom thiab txiav kab txaij kom qhov kawg LED yuav nyob ntawm ib sab xub thawj. Cov hlua LED tuaj yeem tuav nyob rau hauv qhov chaw nrog lub kaus mom, txawm li cas los xij nyob ntawm koj cov qhab thiab cov khoom koj yuav xav tau kom ruaj ntseg LEDs los ntawm kev xaws lossis lo.

Kauj Ruam 3: Txuas Nws

Hlau Nws Up
Hlau Nws Up

Teensy board thiab LEDs yuav ua haujlwm nrog txhua qhov chaw ntawm 3.3v txog 5v rau lub zog. Qhov no yog vim li cas kuv thiaj xaiv siv 3 AAA roj teeb, qhov hluav taws xob tso tawm ntawm 4.5v tau zoo nyob hauv thaj tsam ntawd, thiab lawv muaj sijhawm txaus rau txoj kev uas kuv tau teeb tsa cov LEDs ua haujlwm. Koj yuav tsum muaj peev xwm ua kom zoo dua 8 teev ntawm kev ua haujlwm.

Txuas lub zog

Kuv xaim qhov ua tau zoo thiab tsis zoo los ntawm lub roj teeb lub thawv thiab LEDs ua ke, tom qab ntawd txuas mus rau Teensy hauv qhov chaw tsim nyog. Qhov zoo los ntawm lub roj teeb xav tau txuas nrog rau sab xis sab xis ntawm Teensy hauv daim duab (sau tias Vin ntawm lub rooj tsavxwm), thiab qhov tsis zoo tuaj yeem txuas rau txhua tus lej cim npe GND. Yooj yim muaj ib qho ncaj qha rau ntawm sab nraud ntawm lub rooj tsavxwm, lossis sab xis ntawm Vin tus pin. Daim duab qhia tag nrho pinout rau pawg thawj coj tuaj yeem pom nyob hauv qab ntawm nplooj ntawv no. Thiab qee zaum muaj daim ntawv theej nrog rau thaum koj xaj lub rooj tsavxwm.

Yog tias koj tab tom npaj ua txoj cai uas tsuas muaj ob peb LEDs tig rau ib zaug, koj tuaj yeem ua lub zog ntawm LEDs los ntawm Teensy nws tus kheej, los ntawm kev siv 3.3v tso zis thiab GND, txawm li cas los xij yog tias koj sim rub lub zog ntau dhau koj tuaj yeem ua tau puas lub rooj tsavxwm. Yog li txhawm rau muab koj tus kheej xaiv ntau tshaj nws yog qhov zoo tshaj rau xaim LEDs rau koj lub roj teeb qhov chaw ncaj qha.

Txuas cov LEDs

Kuv tau xaiv Teensy LC rau txoj haujlwm no vim nws muaj tus pin uas ua rau nws yooj yim dua rau xaim xov tooj tuaj tham tau. Hauv qab ntawm pawg thawj coj saib tus pin uas yog thib ob los ntawm daim iav tsom iav Pin #17, tab sis kuj muaj 3.3v rau nws. Qhov no raug xa mus rau qhov rub tawm, thiab ntawm lwm cov laug cam koj yuav tsum tau xaim hluav taws xob tiv thaiv kom muab qhov hluav taws xob ntawd. Hauv Teensy LC koj tuaj yeem xaim los ntawm tus pin ncaj rau koj cov ntaub ntawv LEDs hlau.

Txuas txoj haujlwm sensor

Qee qhov BNO055 cov laug cam muaj ntau nruj dua ntawm qhov hluav taws xob thiab tsuas yog xav tau 3.3v. Vim li no, Kuv xaim Vin ntawm BNO055 pawg thawj coj los ntawm kev mob siab 3.3v tso tawm ntawm Teensy, uas yog tus lej thib 3 ntawm sab xis. Koj tuaj yeem txuas GND ntawm BNO055 rau ib qho GND ntawm Teensy.

BNO055 txoj haujlwm sensor siv I2c tham nrog Teensy. I2c xav tau rub tawm, yog li kuv txuas ob lub 4.7K ohm resistors los ntawm 3.3v tso tawm ntawm Teensy rau tus pin 18 thiab 19. Kuv mam li txuas tus pin 19 rau SCL tus pin ntawm BNO055 board, thiab 18 rau SDA tus pin.

Cov tswv yim thaiv/cov tswv yim

Txhawm rau ua txoj haujlwm no kuv siv cov xaim hluav taws xob ntau dua li tso tseg. Ib qho kom zoo dua rau cov xaim hlau yog thaum siv cov laug cam rau cov laug cam zoo li no. Koj tuaj yeem tshem qee cov xaim, khoov nws mus rau 90 degrees, thiab ntxig nws hla hauv qab ntawm ib qho ntawm cov dav hlau, yog li qhov txiav qhov kawg ntawm cov xov hlau tau nce saum koj lub rooj tsavxwm. Koj tsuas yog xav tau me me ntawm cov laug kom tuav nws mus rau lub davhlau ya nyob twg, thiab koj tuaj yeem txiav tawm qhov yooj yim tshaj.

Cov hlau xaim tuaj yeem nyuaj ua haujlwm nrog raws li nyiam xav nyob li cas nws khoov. Txawm li cas los xij rau txoj haujlwm no uas yog qhov zoo dua. Kuv txiav thiab hloov pauv kuv cov xov hlau nyob rau hauv txoj hauv kev uas qhov kev taw qhia ntawm lub ntsuas qhov ntsuas yuav zoo ib yam li kuv tau tso thiab tshem tawm cov khoom siv hluav taws xob los ntawm lub kaus mom rau kho dua thiab ua haujlwm.

Kauj ruam 4: Programming

Tam sim no txhua yam tau sib sau ua ke koj yuav xav tau Arduino cov cuab yeej ua haujlwm tau zoo. Kuv siv qhov tseeb Arduino IDE (ua haujlwm nrog Linux, Mac, thiab PC). Koj tseem yuav xav tau Teensyduino software los cuam tshuam nrog Teensy board. Txoj haujlwm no hnyav siv lub tsev qiv ntawv FastLED los ua cov xim thiab txoj haujlwm ntawm LEDs.

Calibrating

Thawj qhov koj yuav xav ua yog mus rau Kris Winer qhov zoo tshaj GitHub chaw rau BNO055 thiab rub nws daim BNO_055_Nano_Basic_AHRS_t3.ino kos duab. Nruab qhov chaws ntawd nrog Serial Monitor khiav thiab nws yuav qhia koj yog tias BNO055 pawg thawj coj saib xyuas hauv online raug thiab dhau nws qhov kev sim nws tus kheej. Nws tseem yuav coj koj hla kev ntsuas BNO055, uas yuav muab cov txiaj ntsig zoo ib yam rau koj tom qab.

Pib nrog Fancy LED kos duab

Cov cai rau Fancy LED lub kaus mom tshwj xeeb tau txuas nrog, thiab tseem nyob ntawm kuv GitHub chaw cia khoom. Kuv npaj yuav ua kom muaj kev hloov pauv ntau ntxiv rau cov cai thiab cov ntawd yuav raug tshaj tawm hauv GitHub repo. Cov ntaub ntawv ntawm no cuam tshuam txog cov cai thaum qhov Qhia Qhia no tau tshaj tawm. Tom qab rub tawm thiab qhib daim duab, muaj qee yam uas koj yuav tsum tau hloov. Feem ntau ntawm cov txiaj ntsig tseem ceeb los hloov pauv yog nyob rau sab saum toj raws li #define nqe lus:

Kab 24: #define NUM_LEDS 89 - hloov qhov no mus rau tus lej tiag ntawm LEDs ntawm koj daim kab xev LED

Kab 28: #define SERIAL_DEBUG cuav - koj yuav zaum xav ua qhov no muaj tseeb, yog li koj tuaj yeem pom qhov tso tawm ntawm tus saib xyuas hauv xov tooj

Txoj haujlwm nrhiav pom txoj cai

Nrhiav txoj haujlwm thiab feem ntau ntawm koj qhov tweaking pib ntawm kab 742, thiab hla mus txog 802. Peb tau txais Suab, Yob, thiab Yaw cov ntaub ntawv los ntawm txoj haujlwm ntsuas thiab siv nws los teeb tsa qhov tseem ceeb. Nyob ntawm seb koj cov khoom siv hluav taws xob tau teeb tsa li cas koj yuav xav hloov cov no. Yog tias koj nce lub ntsuas qhov ntsuas nrog lub nti mus rau sab saum toj ntawm lub kaus mom, thiab cov xub nyob ib sab ntawm X luam tawm ntawm lub rooj tsav xwm taw qhia rau sab xub ntiag ntawm lub kaus mom koj yuav tsum pom cov hauv qab no:

  • Suab yog nodding koj lub taub hau
  • Yob tig koj lub taub hau, piv txwv li kov koj pob ntseg rau koj lub xub pwg
  • Yaw yog txoj kev twg. koj tab tom ntsib (North, West, thiab lwm yam).

Yog tias koj lub rooj tsav xwm tau teeb tsa hauv qhov kev qhia sib txawv koj yuav tsum tau pauv Pitch/Roll/Yaw rau lawv coj tus cwj pwm uas koj xav tau.

Txhawm rau kho qhov Roll nqis koj tuaj yeem hloov cov hauv qab no #define tus nqi:

  • ROLLOFFSET: nrog koj lub kaus mom ruaj khov thiab zoo ib yam li nws tuaj yeem ua tau, yog tias Roll tsis yog 0, hloov qhov no los ntawm qhov sib txawv. I.e. yog tias koj pom Yob ntawm -20 thaum koj lub kaus mom nyob hauv nruab nrab, ua qhov no 20.
  • ROLLMAX: tus nqi siab tshaj los siv rau Kev ntsuas Roll. Yooj yim tshaj plaws los nrhiav los ntawm hnav lub kaus mom thiab txav koj lub pob ntseg sab xis ntawm koj lub xub pwg sab xis. Koj yuav xav tau USB cable ntev los ua qhov no thaum siv lub ntsuas saib.
  • ROLLMIN: tus nqi qis tshaj los siv rau Kev ntsuas Roll, rau thaum koj tig koj lub taub hau sab laug

Ib yam nkaus, rau Suab:

  • MAXPITCH - tus nqi siab tshaj thaum koj tab tom nrhiav
  • MINPITCH - tus nqi tsawg kawg thaum koj saib
  • PITCHCENTER - tus nqi suab thaum koj tab tom nrhiav ncaj nraim rau pem hauv ntej

Yog tias koj teeb tsa SERIALDEBUG kom muaj tseeb nyob rau sab saum toj ntawm cov ntawv koj yuav tsum pom qhov txiaj ntsig tam sim no rau Roll/Pitch/Yaw tso tawm rau lub koob saib xyuas kom pab kho qhov txiaj ntsig no.

Lwm yam tsis koj yuav xav hloov

  • MAX_LED_DELAY 35 - qeeb tshaj plaws uas cov LED tuaj yeem txav tau. Qhov no yog nyob rau hauv milliseconds. Nws yog qhov ncua los ntawm kev txav los ntawm ib qho LED mus rau lwm qhov hauv txoj hlua.
  • MIN_LED_DELAY 10 - yoo mov uas cov LED tuaj yeem txav tau. Raws li hais saum toj no nws yog milliseconds.

Xaus

Yog tias koj tau mus deb no, koj yuav tsum muaj lub luag haujlwm zoo, thiab lom zem, LED lub kaus mom! Yog tias koj xav ua ntau dua nrog nws, nplooj ntawv tom ntej muaj qee cov ntaub ntawv paub txog kev hloov chaw, thiab ua koj tus kheej. ntxiv rau qee qhov kev piav qhia txog qhov seem ntawm kuv cov cai ua.

Kauj ruam 5: Advanced thiab Yeem: Hauv Txoj Cai

Kev cuam tshuam & tig pom

Kev ntsuas qhov cuam tshuam/tig tau ua tiav siv lub siab-G lub zog ua haujlwm ntawm BNO055. Koj tuaj yeem hloov kho qhov rhiab heev ntawm nws nrog cov kab hauv qab no hauv initBNO055 ():

  • Kab #316: BNO055_ACC_HG_DURATION - qhov kev tshwm sim yuav tsum kav ntev npaum li cas
  • Kab #317: BNO055_ACC_HG_THRESH - qhov nyuaj yuav cuam tshuam li cas
  • Kab #319: BNO055_GYR_HR_Z_SET - kev sib hloov ceev pib
  • Kab #320: BNO055_GYR_DUR_Z - kev sib hloov ntev npaum li cas txawm tias yuav tsum kav ntev npaum cas

Ob qhov txiaj ntsig yog 8 ntsis binary, tam sim no qhov cuam tshuam tau teeb tsa rau B11000000, uas yog 192 tawm ntawm 255.

Thaum pom qhov cuam tshuam lossis tig tau pom BNO055 teeb tsa tus nqi uas cov cai saib rau sab xis thaum pib ntawm Loop:

// Txheeb xyuas ib qho cuam tshuam cuam tshuam, piv txwv li vim siab G byte intStatus = readByte (BNO055_ADDRESS, BNO055_INT_STATUS); yog (intStatus> 8) {cuam tshuam (); } lwm yog (intStatus> 0) {spin (); }

Saib rau qhov tsis muaj qhov cuam tshuam () kab lus saum toj no hauv cov cai txhawm rau hloov tus cwj pwm ntawm kev cuam tshuam, lossis tsis muaj qhov khoob () hloov pauv tus cwj pwm.

Pab

Kuv tau tsim txoj haujlwm pabcuam yooj yim (tsis muaj teeb meem setAllLeds ()) kom teeb tsa tag nrho cov LEDs rau ib qho xim. Ib qho siv nws los tua lawv txhua tus:

setAllLeds (CRGB:: Dub);

Lossis koj tuaj yeem xaiv xim twg pom los ntawm FastLED lub tsev qiv ntawv:

setAllLeds (CRGB:: Liab);

Kuj tseem muaj fadeAllLeds () muaj nuj nqi uas yuav ua rau tag nrho cov LEDs los ntawm 25%.

Chav kawm Particle

Txhawm rau kom yooj yim yooj yim thaiv kuv xav siv ib txoj hlua ntawm LEDs, tab sis kom lawv coj zoo li ntau txoj hlua. Txij li qhov no yog kuv thawj zaug kuv xav ua kom yooj yim li sai tau, yog li kuv kho ib txoj hlua li ob, nrog nruab nrab LED (s) nyob ntawd qhov sib faib yuav yog. Txij li thaum peb tuaj yeem muaj tus lej lossis tus lej sib txawv, peb yuav tsum suav nrog qhov ntawd. Kuv pib nrog qee qhov kev hloov pauv thoob ntiaj teb:

/ * * Hloov pauv thiab ntim rau LEDs */ CRGB coj [NUM_LEDS]; zoo li qub unsigned int curLedDelay = MAX_LED_DELAY; zoo li qub int centerLed = NUM_LEDS / 2; zoo li qub int maxLedPos = NUM_LEDS / 2; zoo li qub bool oddLeds = 0; zoo li qub bool particleDir = 1; zoo li qub bool speedDir = 1; unsigned ntev dirCount; unsigned ntev hueCount;

Thiab qee qhov chaws hauv teeb ():

yog (NUM_LEDS % 2 == 1) {oddLeds = 1; maxLedPos = NUM_LEDS/2; } lwm {oddLeds = 0; maxLedPos = NUM_LEDS/2 - 1; }

Yog tias peb muaj cov lej sib txawv, peb xav siv 1/2 point ua qhov nruab nrab, txwv tsis pub peb xav tau 1/2 point - 1. Qhov no yooj yim pom nrog 10 lossis 11 LEDs:

  • 11 LEDs: 11/2 nrog cov lej yuav tsum ntsuas txog 5. thiab cov lej suav los ntawm 0. Yog li 0 - 4 yog ib nrab, 6 - 10 yog lwm qhov ib nrab, thiab 5 yog nruab nrab ntawm lawv. Peb kho #5 hauv qhov no zoo li yog nws yog ib feem ntawm ob qho tib si, piv txwv li nws yog #1 rau ob qho tib si cov hlua ntawm LEDs
  • 10 LEDs: 10/2 yog 5. Tab sis txij li lub computer suav los ntawm 0 peb yuav tsum tshem tawm ib qho. Tom qab ntawd peb muaj 0 - 4 rau ib nrab, thiab 5 - 9 rau lwm qhov. #1 rau thawj txoj hlua yuav yog 4, thiab #1 rau txoj hlua thib ob yuav yog #5.

Tom qab ntawd hauv peb cov lej me me peb yuav tsum ua qee qhov suav los ntawm peb txoj haujlwm tag nrho mus rau txoj haujlwm tiag tiag ntawm txoj hlua LED:

yog (oddLeds) {Pos1 = centerLed + currPos; Pos2 = centerLed - currPos; } lwm {Pos1 = centerLed + currPos; Pos2 = (centerLed -1) - currPos; }

Txoj cai tseem muaj cov xwm txheej uas cov khoom tuaj yeem hloov pauv cov lus qhia, yog li peb kuj yuav tsum coj mus rau hauv tus account:

yog (particleDir) {yog ((currPos == NUM_LEDS/2) && oddLeds) {currPos = 0; } lwm tus yog ((currPos == NUM_LEDS/2 - 1) && (! oddLeds)) {currPos = 0; } lwm {currPos ++; }} lwm {yog ((currPos == 0) && oddLeds) {currPos = centerLed; } lwm tus yog ((currPos == 0) && ((oddLeds))) {currPos = centerLed - 1; } lwm {currPos--; }}

Yog li peb siv cov kev taw qhia (particleDir), txhawm rau suav qhov LED yuav tsum tau teeb tom ntej, tab sis peb kuj yuav tsum txiav txim siab yog tias peb tau mus txog qhov kawg tiag tiag ntawm txoj hlua LED, lossis peb qhov chaw nruab nrab, uas tseem ua qhov kawg rau txhua ntawm cov hlua virtual.

Thaum peb tau xam tag nrho qhov ntawd, peb teeb lub teeb tom ntej raws li qhov tsim nyog:

yog (particleDir) {yog (oddLeds) {Pos1 = centerLed + currPos; Pos2 = centerLed - currPos; } lwm {Pos1 = centerLed + currPos; Pos2 = (centerLed -1) - currPos; }} lwm {yog (oddLeds) {Pos1 = centerLed - currPos; Pos2 = centerLed + currPos; } lwm {Pos1 = centerLed - currPos; Pos2 = (centerLed -1) + currPos; }} leds [Pos1] = CHSV (currHue, 255, 255); leds [Pos2] = CHSV (currHue, 255, 255); FastLED.show ();}

Vim li cas thiaj ua hoob no txhua? Raws li nws yog, qhov no yooj yim heev thiab tsis tas yuav tsum tau nyob hauv chav kawm. Txawm li cas los xij kuv muaj phiaj xwm yav tom ntej los hloov kho cov cai kom tso cai rau ntau dua ib qho me me tshwm sim nyob rau ib lub sijhawm, thiab muaj qee qhov ua haujlwm thim rov qab thaum lwm tus tab tom yuav mus tom ntej. Kuv xav tias muaj qee qhov muaj txiaj ntsig zoo heev rau kev tshawb pom kiv siv ntau qhov me me.

Pom zoo: