Cov txheej txheem:

LED Kauv Tsob Ntoo: 4 Cov Kauj Ruam (nrog Duab)
LED Kauv Tsob Ntoo: 4 Cov Kauj Ruam (nrog Duab)

Video: LED Kauv Tsob Ntoo: 4 Cov Kauj Ruam (nrog Duab)

Video: LED Kauv Tsob Ntoo: 4 Cov Kauj Ruam (nrog Duab)
Video: Rau Siab Kawm Ntawd Maiv Twm & Me Nyuam Kub (Tub Hmoov) New Song 2023-2024 2024, Hlis ntuj nqeg
Anonim
LED Kauv Tsob Ntoo
LED Kauv Tsob Ntoo
LED Kauv Tsob Ntoo
LED Kauv Tsob Ntoo
LED Kauv Tsob Ntoo
LED Kauv Tsob Ntoo

Kuv nyiam txhua hom LED strips. Kuv ua lub teeb zaj sawv zoo nrog lawv. Txawm tias cov uas tsis tuaj yeem hais qhia tau muaj txiaj ntsig. Kuv tau ua lub teeb ci kev lag luam sab nraum zoov lub teeb los ntawm kev txuas lawv mus rau qhov tsis muaj kab tav tav li ntawd thaum kuv tsob ntoo kauv tawg tawm kuv txiav txim siab qhwv qhov ntev ntawm cov coj coj los puag ncig nws.

Kauj ruam 1: Tswj

Maub los
Maub los
Maub los
Maub los
Maub los
Maub los

Kuv txiav txim siab siv cov leds RGB tsis tuaj yeem hais txog. Qhov no txhais tau tias kuv tuaj yeem muaj cov txheej txheem ua haujlwm tab sis txhua lub leds hloov xim ib txhij. Qhov no kuj txhais tau tias xav tau tus tswj hwm. Kuv tuaj yeem tau siv ib qho arduino uno thiab tau ua thawj qhov kev sim siv daim thaiv npog RGB tab sis xaus nrog kev siv ib lub rooj tsav xwm kev cai nrog liab qab Atmega328 nti. Tsuas yog yuav tsum tau hloov lub phiaj xwm phiaj xwm thiab ua haujlwm ncaj qha.

Kuv muaj cov laug cam no tshuav los ntawm lwm cov phiaj xwm teeb. Xav tias dawb los siv tus nqi pheej yig inline preprogrammed maub los zoo li kuv tau ua ntawm kuv lub kaus xwb.

Kuv tau xaus siv qhov kev sib tw qeeb crossfade ua lub hauv paus rau tsob ntoo.

/** Code rau hla-fading 3 LEDs, liab, ntsuab thiab xiav (RGB) * Txhawm rau tsim kom ploj, koj yuav tsum ua ob yam: * 1. Piav cov xim uas koj xav kom tso tawm * 2. Teev daim ntawv xaj uas koj xav tau lawv kom ploj mus * * DESCRIBING COLOR: * Cov xim tsuas yog ib qho ntawm peb feem pua, 0-100, * tswj cov liab, ntsuab thiab xiav LEDs * * Liab yog LED liab tag nrho, xiav thiab ntsuab tawm * int liab = {100, 0, 0} * Dim dawb yog tag nrho peb lub LEDs ntawm 30% * int dimWhite = {30, 30, 30} * thiab lwm yam. * * Qee qhov xim ib txwm muab rau hauv qab no, lossis ua koj tus kheej * * LUS ZOO TSO CAI: * Hauv qhov tseem ceeb ntawm txoj haujlwm, koj yuav tsum teev cov xaj * koj xav kom cov xim tshwm rau hauv, piv txwv. * crossFade (liab); * crossFade (ntsuab); * crossFade (xiav); * * Cov xim yuav tshwm nyob rau hauv qhov kev txiav txim ntawd, ploj mus ntawm * ib qho xim thiab mus rau tom ntej * * Ntxiv rau, muaj 5 qhov kev xaiv uas koj tuaj yeem kho: * 1. Thawj lub xim tau teeb rau dub (yog li thawj xim ploj mus) hauv), tab sis * koj tuaj yeem teeb tsa thawj xim kom muaj lwm yam xim * 2. Lub voj sab hauv ua haujlwm rau 1020 kev npaj; qhov 'tos' sib txawv * teeb tsa lub sijhawm kwv yees ntawm kev hla ib leeg. Hauv kev xav, * a 'tos' ntawm 10 ms yuav tsum ua kom hla ntawm ~ 10 vib nas this. Hauv * kev coj ua, lwm txoj haujlwm cov cai tau ua qhov qeeb no * nqis mus ~ 11 vib nas this ntawm kuv lub rooj tsavxwm. YMMV. * 3. Yog tias 'rov ua dua' tau teeb tsa rau 0, qhov kev zov me nyuam yuav voj mus tas li. * yog tias nws tau teeb tsa tus lej, nws yuav rov ua cov lej ntawd, * tom qab ntawd nres ntawm cov xim kawg hauv ntu. (Teeb 'rov qab' rau 1, * thiab ua rau xim kawg xim dub yog tias koj xav kom nws ploj mus thaum kawg.) * 4. Muaj kev xaiv 'tuav' sib txawv, uas pasues * qhov kev pab cuam rau 'tuav' milliseconds thaum ib cov xim tiav, * tab sis ua ntej xim tom ntej pib. * 5. Teev tus DEBUG chij rau 1 yog tias koj xav kom debugging tso tawm kom raug * xa mus rau tus lej saib. * * Sab hauv ntawm txoj haujlwm tsis nyuab, tab sis lawv * ua rau me ntsis fussy - kev ua haujlwm sab hauv tau piav qhia * hauv qab lub ntsiab lus. * * Plaub Hlis 2007, Clay Shirky *

/ Tso zis

int grnPin = 9; // Ntsuab LED, txuas nrog tus lej digital 10 int redPin = 10; // Liab LED, txuas nrog tus lej digital 9 int bluPin = 11; // Xiav LED, txuas nrog tus lej digital 11

// Xim arrays

int dub [3] = {0, 0, 0}; int dawb [3] = {100, 100, 100}; int liab [3] = {100,0, 0}; ntsuab ntsuab [3] = {0, 100, 0}; int xiav [3] = {0, 0, 100}; int daj [3] = {40, 95, 0}; int dimWhite [3] = {30, 30, 30}; // lwm

// Teeb thawj xim

int redVal = dub [0]; int grnVal = dub [1]; int bluVal = dub [2];

int tos = 3; // 10ms sab hauv crossFade ncua; nce rau qeeb qeeb

int tuav = 0; // Yeem xaiv tuav thaum xim tiav, ua ntej crossFade int DEBUG = 0; // DEBUG txee; yog teem rau 1, yuav sau qhov tseem ceeb rov qab ntawm cov lej int loopCount = 60; // Npaum li cas yuav tsum ceeb toom DEBUG? int rov = 0; // Muaj pes tsawg zaus peb yuav tsum tau ua ntej nres? (0 rau tsis nres) int j = 0; // Loop txee rau rov ua dua

// Pib hloov xim xim

int prevR = redVal; int prevG = grnVal; int prevB = bluVal;

// Teeb tsa cov LED tawm

teeb tsa tsis muaj dab tsi () {pinMode (redPin, OUTPUT); // teeb tsa tus pin raws li tso zis pinMode (grnPin, OUTPUT); pinMode (bluPin, OUTPUT);

yog (DEBUG) {// Yog tias peb xav pom qhov tseem ceeb rau kev debugging …

Serial.begin (9600); //… teeb tsa cov ntawv tso tawm}}

// Qhov haujlwm tseem ceeb: teev qhov kev txiav txim ntawm crossfades

void loop () {crossFade (liab)); crossFade (ntsuab); crossFade (xiav); crossFade (daj);

yog tias (rov ua dua) {// Puas yog peb rov ua dua qhov tsawg kawg ntawm lub sijhawm?

j += 1; yog (j> = rov hais dua) {// Puas yog peb tseem tsis tau muaj? tawm (j); // Yog tias muaj, nres. }}}

/* Cov kab hauv qab no yog MATH - Koj YUAV TSUM tsis xav hloov qhov no rau cov hauv paus

* * Qhov haujlwm ua haujlwm zoo li no: * Xav txog qhov crossfade uas txav cov LED liab los ntawm 0-10, * ntsuab los ntawm 0-5, thiab xiav los ntawm 10 txog 7, hauv * kaum kauj ruam. * Peb xav suav 10 qib thiab nce lossis * txo cov xim hauv qhov sib npaug sib npaug nce ntxiv. * Xav txog a + qhia nce tus nqi los ntawm 1, thiab a - * sib npaug txo nws. Peb 10 kauj ruam ploj yuav zoo li: * * 1 2 3 4 5 6 7 8 9 10 * R + + + + + + + + + + + * G + + + + + + * B - - - * * Cov liab nce los ntawm 0 txog 10 hauv kaum kauj ruam, ntsuab los ntawm * 0-5 hauv 5 kauj ruam, thiab xiav poob los ntawm 10 txog 7 hauv peb qib. * * Hauv qhov haujlwm tiag, cov xim feem pua tau hloov pauv mus rau * 0-255 qhov tseem ceeb, thiab muaj 1020 qib (255 * 4). * * Txhawm rau txiav txim siab loj npaum li cas ib kauj ruam yuav tsum muaj ntawm ib qho- lossis * nqis-zuam ntawm ib qho ntawm cov txiaj ntsig LED, peb hu rau calculStep (), * uas suav qhov sib txawv ntawm qhov pib thiab qhov tseem ceeb, * thiab tom qab ntawd faib qhov sib txawv los ntawm 1020 txhawm rau txiav txim siab qhov loj ntawm qib * ntawm kev hloov kho hauv tus nqi. */

int calculStep (int prevValue, int endValue) {

int kauj ruam = endValue - prevValue; // Qhov sib txawv tag nrho yog dab tsi? yog (kauj ruam) {// Yog tias nws tsis xoom, kauj ruam = 1020/kauj ruam; // faib los ntawm 1020} rov qab nqis; }

/* Cov haujlwm tom ntej yog xamVal. Thaum lub voj nqi, kuv, * nce mus txog qhov loj me uas tsim nyog rau ib qho ntawm * xim, nws nce lossis txo tus nqi ntawm cov xim ntawd los ntawm 1. * (R, G, thiab B yog suav txhua qhov cais.) */

int calculVal (int qib, int val, int kuv) {

yog ((kauj ruam) && i % kauj ruam == 0) {// Yog tias kauj ruam tsis yog xoom thiab nws lub sijhawm hloov pauv tus nqi, yog (kauj ruam> 0) {// nce tus nqi yog kauj ruam yog qhov zoo… val += 1; } lwm yog (kauj ruam 255) {val = 255; } lwm yog (val <0) {val = 0; } rov qab val; }

/* crossFade () hloov qhov feem pua xim rau a

* 0-255 ntau, tom qab loops 1020 zaug, txheeb xyuas seb puas * tus nqi xav tau hloov tshiab txhua lub sijhawm, tom qab ntawv sau * tus nqi xim rau qhov pins raug. */

tsis muaj dab tsi crossFade (int xim [3]) {

// Hloov mus rau 0-255 int R = (xim [0] * 255) / 100; int G = (xim [1] * 255) / 100; int B = (xim [2] * 255) / 100;

int stepR = calculStep (prevR, R);

int stepG = calculStep (prevG, G); int stepB = calculStep (prevB, B);

rau (int i = 0; i <= 1020; i ++) {redVal = calculVal (stepR, redVal, i); grnVal = calculVal (stepG, grnVal, kuv); bluVal = calculVal (stepB, bluVal, kuv);

analogWrite (redPin, redVal); // Sau qhov txiaj ntsig tam sim no rau LED pins

analogWrite (grnPin, grnVal); analogWrite (bluPin, bluVal);

ncua (tos); // Ncua rau 'tos' milliseconds ua ntej rov ua lub voj

yog tias (DEBUG) {// Yog tias peb xav tau cov ntawv tso tawm, luam tawm ntawm

yog (i == 0 lossis i % loopCount == 0) {// pib, thiab txhua lub voj voos suav lub sijhawm Serial.print ("Loop/RGB: #"); Serial.print (kuv); Serial.print ("|"); Serial.print (redVal); Serial.print (" /"); Serial.print (grnVal); Serial.print (" /"); Serial.println (bluVal); } DEBUG += 1; }} // Hloov kho qhov txiaj ntsig tam sim no rau lub voj tom ntej prevR = redVal; prevG = grnVal; prevB = bluVal; ncua (tuav); // Ncua rau xaiv 'tos' milliseconds ua ntej rov pib lub voj}

Kauj ruam 2: Muab tsob ntoo

Muab ntoo
Muab ntoo
Muab ntoo
Muab ntoo
Muab ntoo
Muab ntoo
Muab ntoo
Muab ntoo

Kuv siv cov dej tsis thwj vim cov no yuav nyob sab nraum zoov. Lawv tau lo ntawm lawv tus kheej tab sis kuv tau nrawm nrog cov xov hlau txuas kom ntseeg tau tias lawv nyob twj ywm. Yooj yim thiab yooj yim hack. Kev muaj peev xwm ua kom muaj zog ntawm kab txaij ua rau nws yooj yim los pub lub zog tso rau hauv qab thiab tau txais lub zog tawm sab saum toj mus rau lub hnub qub.

Kauj Ruam 3: Tsis Txhob hnov qab Lub Hnub Qub nyob saum

Tsis txhob hnov qab lub Hnub Qub nyob saum
Tsis txhob hnov qab lub Hnub Qub nyob saum
Tsis txhob hnov qab lub Hnub Qub nyob saum
Tsis txhob hnov qab lub Hnub Qub nyob saum
Tsis txhob hnov qab lub Hnub Qub nyob saum
Tsis txhob hnov qab lub Hnub Qub nyob saum
Tsis txhob hnov qab lub Hnub Qub nyob saum
Tsis txhob hnov qab lub Hnub Qub nyob saum

Rau lub hnub qub Kuv tau siv ib khub ntawm 10W chips kom tau txais kev saib xyuas. Kuv muab lawv tso rau ntawm daim ntawv tooj liab ua lub rhaub dej kub. Kuv tuaj yeem siv daim kab xev ntau dua vim tias tshuav me ntsis.

Kauj ruam 4: Sim Nws Tawm

Image
Image

Thawj zaug tau ua kom nrawm nrawm dhau….

Thaum kuv calmed nws cia nws saib zoo nkauj heev.

Pom zoo: