Cov txheej txheem:

RaspberryPi: Teem ib qho LED hauv thiab Tawm: 4 Kauj Ruam (nrog Duab)
RaspberryPi: Teem ib qho LED hauv thiab Tawm: 4 Kauj Ruam (nrog Duab)

Video: RaspberryPi: Teem ib qho LED hauv thiab Tawm: 4 Kauj Ruam (nrog Duab)

Video: RaspberryPi: Teem ib qho LED hauv thiab Tawm: 4 Kauj Ruam (nrog Duab)
Video: Часы G-Shock до 250 долларов-15 лучших часов Casio G до 250 доллар... 2024, Hlis ntuj nqeg
Anonim
RaspberryPi: Teem ib qho LED hauv thiab Tawm
RaspberryPi: 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 qhia yuav ua li cas dim ib qho LED ntawm tus nqi sib npaug thiab yuav ua li cas thiaj ploj nws hauv thiab tawm.

Koj yuav xav tau:

  • RaspberryPi (Kuv siv Pi qub, kuv Pi-3 tau siv, tab sis Pi yuav ua haujlwm.)
  • Cov qhob cij
  • 5 hli liab LED
  • 330 Ω Resistor (Tsis tseem ceeb 220-560 Ω yuav ua haujlwm.)
  • Hookup Hlau

Pi-cobbler Kuv siv los ntawm Adafruit tsis tsim nyog, tab sis nws ua rau daim ntawv qhia zaub mov yooj yim dua.

WiringPi yog teeb tsa cov tsev qiv ntawv rau phiaj xwm RaspberryPi hauv C. Cov lus qhia rau rub tawm, teeb tsa thiab siv yog nyob ntawm

Txhawm rau teeb tsa wiringPi ua raws cov lus qhia ntawm nplooj ntawv no:

Txhawm rau kom tau txais cov npe wiringPi tus lej tus lej nkag mus gpio nyeem ntawv ntawm kab hais kom ua.

Hauv cov ntawv tshiab ntawm Raspian wiringPi tau teeb tsa los ntawm lub neej ntawd.

Kauj Ruam 1: Pulse Width Modulation

Mem tes dav tes taws los piav
Mem tes dav tes taws los piav
Mem tes dav tes taws los piav
Mem tes dav tes taws los piav
Mem tes dav tes taws los piav
Mem tes dav tes taws los piav

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 wiringPi pwmWrite (tus pin, n) ua haujlwm qhov twg n muaj tus nqi los ntawm 0 txog 255. Yog tias 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: LED thiab Resistor

LED thiab Resistor
LED thiab Resistor

Qhov no tsis yog qhov xav tau, tab sis muaj ob peb yam ntawm cov no tuaj yeem ua rau ua mov ci yooj yim dua.

Solder tus tiv thaiv kom luv luv ntawm LED. Siv 220-560 Ohm resistor.

Kauj ruam 3: Un-even 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 wiringPi tus pin 1 vim tias koj xav tau siv PWM qhib tus pin. Sau cov program 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.

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

* Sau ua ke: gcc -o fade1 -Wall -I/usr/local/suav nrog -L/usr/local/lib * fade1.c -lwiringPi * * Ua: sudo./fade1 * * Txhua tus lej tus lej yog xaimPi tus lej tshwj tsis yog lwm yam tshwj xeeb. ********************************************************** ****** ****************/ #include int main () {wiringPiSetup (); // Teeb tsa xav tau los ntawm wiringPi pinMode (1, PWM_OUTPUT); // pwmSetMode (PWM_MODE_MS); // Mark/Space mode int kuv; thaum (1) {rau (i = 255; i> -1; i--) {pwmWrite (1, i); ncua (10); } rau (i = 0; i <256; i ++) {pwmWrite (1, i); 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 4: Kauj Ruam 4: nce thiab nqis hauv Ib Rau Rau (), thiab ntawm Tus Nqi Txawm

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.

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. Sib sau ua ke thiab ua haujlwm qhov no thiab koj yuav pom tias LED yuav ploj mus thiab tawm ntawm qhov tsis tu ncua.

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

* Sau: gcc -o fade1 -Wall -I/usr/local/suav nrog -L/usr/local/lib * fade2.c -lwiringPi * * Ua: sudo./fade2 * * Txhua tus lej tus lej yog xaimPi tus lej tshwj tsis yog lwm yam tshwj xeeb. ********************************************************** ****** ****************/ #include int main () {wiringPiSetup (); // Teeb tsa xav tau los ntawm wiringPi pinMode (1, PWM_OUTPUT); // pwmSetMode (PWM_MODE_MS); // Kos/Hom chaw thaum (1) {int i; int x = 1; rau (i = 0; i> -1; i = i + x) {int d = (16 -i/16)^2; // calc inverse square ntawm qhov ntsuas pwmWrite (1, i); ncua (d); yog (i == 255) x = -1; // hloov kev taw qhia ntawm qhov siab}}}

Pom zoo: