Cov txheej txheem:

RGB LED Nrog Arduino Uno R3: 7 Cov Kauj Ruam
RGB LED Nrog Arduino Uno R3: 7 Cov Kauj Ruam

Video: RGB LED Nrog Arduino Uno R3: 7 Cov Kauj Ruam

Video: RGB LED Nrog Arduino Uno R3: 7 Cov Kauj Ruam
Video: NOOBS PLAY CLASH ROYALE FROM START LIVE 2024, Kaum ib hlis
Anonim
RGB LED Nrog Arduino Uno R3
RGB LED Nrog Arduino Uno R3

Yav dhau los peb tau siv PWM thev naus laus zis los tswj LED kom ci thiab tsaus. Hauv zaj lus qhia no, peb yuav siv nws los tswj lub RGB LED kom nyem ntau yam xim. Thaum sib txawv PWM qhov tseem ceeb tau teeb tsa rau R, G, thiab B pins ntawm LED, nws qhov ci yuav txawv. Thaum peb qhov sib txawv xim sib xyaw, peb tuaj yeem pom tias RGB LED ua rau pom cov xim sib txawv.

Kauj Ruam 1: Cheeb Tsam

- Arduino Uno board * 1

- USB cable * 1

- Tus tiv thaiv (220Ω) * 1

- RGB LED * 3

- Daim phiaj * 1

- Jumper xov hlau

Kauj Ruam 2: Txoj Cai

RGB LED txhais tau tias liab, xiav thiab ntsuab LEDs. RGB LED tau

tso cov xim sib txawv los ntawm kev sib xyaw 3 xim yooj yim liab, ntsuab thiab xiav. Yog li nws tiag tiag suav nrog 3 cais LEDs liab, ntsuab thiab xiav ntim rau hauv ib rooj plaub. Tias yog vim li cas nws muaj 4 tus coj, ib tus coj rau txhua ntawm 3 xim thiab ib qho cathode lossis anode nyob ntawm seb hom RGB LED. Hauv qhov kev qhia no kuv yuav siv cov cathode ib txwm.

Kauj Ruam 3: Daim Duab Schematic

Schematic Daim duab
Schematic Daim duab

Kauj ruam 4: Cov txheej txheem

Cov txheej txheem
Cov txheej txheem
Cov txheej txheem
Cov txheej txheem

Hauv qhov kev sim no, peb tseem yuav siv PWM uas, yog tias koj tau ua raws cov lus qhia txog tam sim no, koj twb muaj kev nkag siab yooj yim ntawm. Ntawm no peb tawm tswv yim tus nqi nruab nrab ntawm 0 thiab 255 rau peb tus pin ntawm RGB LED kom nws pom cov xim sib txawv. Tom qab txuas tus pin ntawm R, G, thiab B rau qhov txwv tam sim no, txuas lawv rau tus pin 9, tus pin 10, thiab tus pin 11 feem. Tus pin ntev tshaj (GND) ntawm LED txuas rau GND ntawm Uno. Thaum peb tus pin raug muab sib txawv PWM qhov tseem ceeb, RGB LED yuav tso tawm xim sib txawv.

Kauj ruam 1:

Tsim lub voj voog.

Kauj ruam 2:

Rub tawm cov cai los ntawm

Kauj ruam 3:

Tshaj tawm cov duab kos rau Arduino Uno board

Nyem rau Upload icon txhawm rau upload cov cai rau pawg tswj hwm.

Yog tias "Ua tiav uploading" tshwm nyob rau hauv qab ntawm lub qhov rais, nws txhais tau hais tias daim duab tau ua tiav tiav.

Ntawm no koj yuav tsum pom RGB LED nyem ncig liab, ntsuab, thiab xiav ua ntej, tom qab ntawd liab, txiv kab ntxwv, daj, ntsuab, xiav, indigo, thiab ntshav.

Kauj ruam 5: Code

// RGBLED

// Cov

RGB LED yuav tshwm liab, ntsuab, thiab xiav ua ntej, tom qab ntawd liab, txiv kab ntxwv, daj, ntsuab, xiav, indigo, thiab ntshav.

// Web site: www.primerobotics.in

/*************************************************************************/

qhov

int redPin = 11; // R petal ntawm RGB LED module txuas nrog tus pin 11

qhov

int greenPin = 10; // G petal ntawm RGB LED module txuas nrog tus pin 10

qhov

int bluePin = 9; // B petal ntawm RGB LED module txuas nrog tus pin 9

/**************************************************************************/

tsis muaj dab tsi

teeb ()

{

pinMode (redPin, OUTPUT); // teeb tsa redPin

los ua qhov tso tawm

tus pinMode (greenPin, OUTPUT); // teev cov

greenPin los ua qhov tso tawm

tus pinMode (bluePin, OUTPUT); // teeb tsa bluePin

los ua qhov tso tawm

}

/***************************************************************************/

tsis muaj dab tsi

loop () // khiav ntau thiab ntau dua

{

// Cov xim yooj yim:

xim (255, 0, 0); // tig RGB LED liab

ncua (1000); // ncua rau 1 thib ob

xim (0, 255, 0); // tig lub RGB LED

ntsuab

ncua (1000); // ncua rau 1 thib ob

xim (0, 0, 255); // tig lub RGB LED

xiav

ncua (1000); // ncua rau 1 thib ob

// Piv txwv cov xim sib xyaw:

xim (255, 0, 252); // tig lub RGB LED

liab

ncua (1000); // ncua rau 1 thib ob

xim (237, 109, 0); // tig lub RGB LED

txiv kab ntxwv

ncua (1000); // ncua rau 1 thib ob

xim (255, 215, 0); // tig lub RGB LED

daj

ncua (1000); // ncua rau 1 thib ob

xim (34, 139, 34); // tig lub RGB LED

ntsuab

ncua (1000); // ncua rau 1 thib ob

xim (0, 112, 255); // tig RGB LED xiav

ncua (1000); // ncua rau 1 thib ob

xim (0, 46, 90); // tig lub RGB LED indigo

ncua (1000); // ncua rau 1 thib ob

xim (128, 0, 128); // tig lub RGB LED

liab doog

ncua (1000); // ncua rau 1 thib ob

}

/******************************************************/

tsis muaj dab tsi

xim (tsis kos npe liab, tsis kos npe ntsuab, tsis kos npe xiav) // xim tsim muaj nuj nqi

{

analogWrite (redPin, liab);

analogWrite (greenPin, ntsuab);

analogWrite (bluePin, xiav);

}

/******************************************************/

Pom zoo: