Cov txheej txheem:

LED Dimmer Nrog Potentiometer: 5 Kauj Ruam (nrog Duab)
LED Dimmer Nrog Potentiometer: 5 Kauj Ruam (nrog Duab)

Video: LED Dimmer Nrog Potentiometer: 5 Kauj Ruam (nrog Duab)

Video: LED Dimmer Nrog Potentiometer: 5 Kauj Ruam (nrog Duab)
Video: Varying brightness of LED using PWM on Rpi 2024, Hlis ntuj nqeg
Anonim
LED Dimmer Nrog Potentiometer
LED Dimmer Nrog Potentiometer

Nov yog cov lus qhia qhia koj yuav siv lub hwj chim li cas kom dim ib qho LED.

Kauj ruam 1: Cov ntaub ntawv

Khoom siv
Khoom siv
Khoom siv
Khoom siv
Khoom siv
Khoom siv
Khoom siv
Khoom siv
  1. Arduino
  2. Khoos phis tawj
  3. Cov qhob cij
  4. LED
  5. 5 Txiv neej cov xov hlau
  6. Potentiometer
  7. USB cable

Kauj ruam 2: Pib

Pib Pib
Pib Pib

Txuas Arduino rau hauv computer nrog USB cable.

Kauj Ruam 3: Kev thaiv kab hlau

Thaiv
Thaiv
Thaiv
Thaiv
Thaiv
Thaiv

Tom qab Arduino tau txuas rau hauv lub khoos phis tawj nrog lub xaim USB, peb yuav siv thawj lub xov hlau thiab tso ib kawg rau hauv av thiab lwm qhov rau hauv j1. Tom qab ntawd koj yuav tso tus xov tooj thib ob los ntawm A0 rau j3. Tom qab ntawd Koj yuav tso cov xaim thib peb los ntawm 5v rau j5.

Tom qab ntawd koj yuav muab cov xov plaub los ntawm D9 txog j15. Tom qab ntawd tus xov tooj thib tsib thiab zaum kawg los ntawm hauv av mus rau j17.

Kauj Ruam 4: Potentiometer thiab Teeb LED

Potentiometer thiab teeb LED
Potentiometer thiab teeb LED

Muab lub pob qhov rooj tig mus deb ntawm cov xov hlau. Txuas nws mus rau f1 f3 thiab f5. Tom qab ntawd coj tus LED tso ceg ntev dua rau hauv f15 thiab luv dua hauv f17.

Kauj ruam 5: Txoj Cai

Nov yog cov kev hloov pauv uas qhia lub khoos phis tawj cov lus tshwj xeeb txhais li cas:

int potPin = A0; Qhov no qhia rau lub khoos phis tawj hais tias qhov nruab nrab ntawm lub hwj chim, uas peb hu ua potPin, tau txuas rau hauv A0 int readValue; Qhov no qhia rau lub khoos phis tawj tias thaum twg peb hais tias nyeem tau qhov muaj nqis nws txhais tau tias nyeem lub hwj chim

Nov yog Void Setup uas tsuas yog tshwm sim ib zaug los teeb tsa rau qhov seem ntawm cov cai:

teeb tsa tsis muaj dab tsi () {Qhov no tsuas yog qhia koj tias qhov no yog qhov pib ntawm Void Setup

pinMode (9, NTAWV); Qhov no teeb tsa lub teeb kom nws tuaj yeem qhib tom qab

pinMode (potPin, INPUT); Qhov no teeb tsa lub potentiometer yog li peb tuaj yeem siv nws tom qab

Tshooj tom ntej yog lub voj void uas sau ntau thiab ntau dua kom txog thaum koj nres nws.

void voj () {

readValue = analogRead (potPin); Qhov no qhia rau lub khoos phis tawj nyeem lub hwj chim thaum twg peb hais tias nyeem tau tus nqi.

readValue = daim ntawv qhia (readValue, 0, 1023, 0, 255); Qhov no hloov cov lej los ntawm lub zog uas yog los ntawm 0-1023, rau tus lej rau LED uas yog los ntawm 0-255.

analogWrite (9, nyeem Tus Nqi); Qhov no qhia rau lub khoos phis tawj kom pom lub teeb ci LED ntawm qhov ci ntsa iab uas lub hwj chim tau qhia rau nws.

}

Nov yog tag nrho cov cai los ntawm nws tus kheej:

int potPin = A0; int readValue = 0;

void teeb tsa () {

pinMode (9, NTAWV);

pinMode (potPin, INPUT);}

void voj () {

readValue = analogRead (potPin);

readValue = daim ntawv qhia (readValue, 0, 1023, 0, 255);

analogWrite (9, nyeemValue);}

Pom zoo: