Cov txheej txheem:

Teem ib qho LED hauv thiab Tawm: 3 Kauj Ruam
Teem ib qho LED hauv thiab Tawm: 3 Kauj Ruam

Video: Teem ib qho LED hauv thiab Tawm: 3 Kauj Ruam

Video: Teem ib qho LED hauv thiab Tawm: 3 Kauj Ruam
Video: Tus Neeg Ruam - R-Lin Thoj | New Song [ Official MV ] Nkauj Tawm Tshiab 2023 Hmong Song 2023 2024, Hlis ntuj nqeg
Anonim
Teem ib qho LED hauv thiab Tawm
Teem ib qho LED hauv thiab Tawm

Cov theem hauv qab no yog kev sim ua piv txwv seb LEDs ua haujlwm li cas. Lawv piav qhia yuav ua li cas dim ib qho LED ntawm tus nqi sib npaug thiab yuav ua li cas kom nws ploj mus thiab tawm.

Koj yuav xav tau:

  • Arduino (Kuv siv duo)
  • Cov qhob cij
  • 5 hli liab LED
  • 330 Ω Resistor (Tsis tseem ceeb 330-560 Ω yuav ua haujlwm.)
  • 22 Kev Ntsuas Cov Khoom Hookup Hlau

Cov ntu xav tau rau cov kev sim no suav nrog hauv txhua qhov khoom siv Arduino pib.

Kauj Ruam 1: Piav Tes Taw Kev Piav Qhia

Pulse Modulation Piav Qhia
Pulse Modulation Piav Qhia
Pulse Modulation Piav Qhia
Pulse Modulation Piav Qhia
Pulse Modulation Piav Qhia
Pulse Modulation Piav Qhia

LEDs ib txwm khiav ntawm tib qhov hluav taws xob tsis hais txog qhov ci ntsa iab. Qhov ci ntsa iab tau txiav txim siab los ntawm ib puag ncig yoj oscillator thiab lub sijhawm uas qhov hluav taws xob siab txiav txim siab qhov ci ci. Qhov no hu ua Pulse Width Modulation (PWM). Qhov no yog tswj los ntawm Arduino analogWrite (tus pin, n) ua haujlwm qhov twg n muaj tus nqi los ntawm 0 txog 255. Cov analogWrite () tso tawm PWM, tsis yog qhov tseeb analog. Yog n = 2 LED yuav ci dua li n = 1. Qhov ci ci ib txwm ob npaug thaum n ob npaug. Yog li n = 255 yuav yog ob zaug ci li n = 128.

Tus nqi ntawm n feem ntau qhia raws li feem pua hu ua lub voj voog ua haujlwm. Cov duab qhia pom oscilloscope taug qab rau 25, 50 thiab 75% kev ua haujlwm.

Kauj ruam 2: Un-even Dimming

Tsis-txawm Dimming
Tsis-txawm Dimming
Tsis-txawm Dimming
Tsis-txawm Dimming

Tsim lub Circuit Court zoo li hauv daim duab. Qhov no zoo ib yam li lub voj voog kom ntsais ib qho LED. Nws siv tus pin 9 vim tias koj xav tau siv PWM qhib tus pin.

Luam/Muab cov duab kos hauv qab no rau hauv Arduino IDE thiab khiav nws.

Koj yuav pom tias qhov ci ntsa iab ntawm LED yog qhov qeeb nws dims. Raws li nws tau ze rau qhov dimmest nws yuav tau dimmer sai heev.

void teeb tsa ()

{pinMode (9, OUTPUT); } void loop () {int tus pin = 9; rau (int i = 255; i> -1; i--) {analogWrite (tus pin, kuv); ncua (10); } rau (int i = 0; i <256; i ++) {analogWrite (tus pin, kuv); ncua (10); }}

}

Cov kauj ruam tom ntej qhia yuav ua li cas dim lub LED ntawm tus nqi tas li, thiab hauv ib qho rau nqe lus.

Kauj Ruam 3: nce thiab nqis hauv ib qho rau ()

Rau LED kom dim ntawm qhov tsis tu ncua ncua () yuav tsum nce ntawm qhov nthuav tawm vim tias ib nrab ntawm lub luag haujlwm yuav ib txwm ua ib nrab qhov ci ntsa iab. Kuv thawj qhov kev xav yog sim siv daim ntawv qhia () ua haujlwm tab sis nws yog kab.

Kab:

int d = (16-i/16)^2;

laij cov xwm txheej hloov pauv ntawm qhov ci ci los txiav txim qhov ncua ntawm qhov ncua.

Luam/Muab cov duab kos hauv qab no rau hauv Arduino IDE thiab koj yuav pom tias LED yuav ploj mus thiab tawm ntawm qhov tsis tu ncua.

void teeb tsa ()

{pinMode (9, OUTPUT); } tsis muaj dab tsi voj () {int x = 1; tus pin = 9; rau (int i = 0; i> -1; i = i + x) {int d = (16 -i/16)^2; analogWrite (tus pin, kuv); ncua (d); yog (i == 255) x = -1; // hloov kev taw qhia ntawm qhov siab tshaj plaws}}

Pom zoo: