Cov txheej txheem:

Hloov ib qho RGB LED Los Ntawm Cov Xim Spectrum Siv Raspberry Pi 2 thiab Kos: 11 Kauj Ruam
Hloov ib qho RGB LED Los Ntawm Cov Xim Spectrum Siv Raspberry Pi 2 thiab Kos: 11 Kauj Ruam

Video: Hloov ib qho RGB LED Los Ntawm Cov Xim Spectrum Siv Raspberry Pi 2 thiab Kos: 11 Kauj Ruam

Video: Hloov ib qho RGB LED Los Ntawm Cov Xim Spectrum Siv Raspberry Pi 2 thiab Kos: 11 Kauj Ruam
Video: Niam tais thiab ntxhais faus vauv dab laug nrog faus puas muaj tseeb 2024, Kaum ib hlis
Anonim
Hloov ib qho RGB LED Los Ntawm Cov Xim Spectrum Siv Raspberry Pi 2 thiab Kos
Hloov ib qho RGB LED Los Ntawm Cov Xim Spectrum Siv Raspberry Pi 2 thiab Kos

Hloov Kho Cov Lus Sau Hnub Tim 25 Lub Ob Hlis, 2016: Kuv tau txhim kho Scratch program thiab rov tsim kho kuv cov lus qhia.

Nyob zoo cov neeg, nrog txoj haujlwm no kuv xav siv Kos rau lub voj voog RGB LED los ntawm cov xim xim.

Muaj ntau qhov haujlwm ua qhov no nrog Arduino, yog li kuv xav paub seb kuv puas tuaj yeem tau txais qhov txiaj ntsig zoo nrog Raspberry Pi.

Kuv thawj zaug sim ntawm qhov kev qhia no tsis zoo heev, yog li kuv tau tshawb fawb me ntsis ntxiv thiab xav tias kuv muaj qee yam uas ua haujlwm tau zoo dua. Thaum kuv tab tom saib xyuas qee qhov haujlwm Arduino txhawm rau nkag siab qhov twg kuv mus yuam kev hauv kuv qhov haujlwm qub, kuv dawm qhov ntawv Arduino zoo heev, uas kuv yuav txuas koj mus rau qhov kawg. Kuv tus phooj ywg Andrew thiab kuv tau siv sijhawm tav su los hloov nws mus rau Kos. Peb tau ua peb qhov zoo tshaj plaws nrog nws thiab kuv vam tias koj yuav sim nws.

Txoj haujlwm no yog ua raws los ntawm kuv cov lus qhia txog kev hloov pauv qhov ci ci ntawm LED siv cov nyees khawm thiab kos uas koj tuaj yeem pom ntawm no:

www.instructables.com/id/PWM-Based-LED-Cont…

Txuas mus rau thawj Arduino Sketch Kuv raws kuv qhov kev pab cuam Kos rau ntawm:

www.arduino.cc/en/Tutorial/DimmingLEDs tus sau Clay Shirky

Kauj Ruam 1: Sib Sau Ua Ke Txhua Yam Koj Yuav Tsum Muaj Rau Txoj Haujlwm no

Sib Sau Ua Ke Txhua Yam Koj Yuav Tsum Muaj Rau Txoj Haujlwm no
Sib Sau Ua Ke Txhua Yam Koj Yuav Tsum Muaj Rau Txoj Haujlwm no
Sib Sau Ua Ke Txhua Yam Koj Yuav Tsum Muaj Rau Txoj Haujlwm no
Sib Sau Ua Ke Txhua Yam Koj Yuav Tsum Muaj Rau Txoj Haujlwm no
Sib Sau Ua Ke Txhua Yam Koj Yuav Tsum Muaj Rau Txoj Haujlwm no
Sib Sau Ua Ke Txhua Yam Koj Yuav Tsum Muaj Rau Txoj Haujlwm no

Cov khoom koj yuav xav tau:

Raspberry Pi nrog Raspian operating system thiab internet txuas

1 x Breadboard

1 x RGB LED (nquag cathode)

3 x 330 ohm resistors (txiv kab ntxwv txiv kab ntxwv xim av)

4 x txiv neej/poj niam breadboard cables

1 x txiv neej/txiv neej breadboard cable (lossis me me ib leeg tub ntxhais jumper cable yog tias koj muaj)

Kauj Ruam 2: Nkag Siab Li Cas Ob Txhais Tes ntawm RGB LED Ua

Nkag Siab Dab Tsi Cov Ceg Ntawm RGB LED Ua
Nkag Siab Dab Tsi Cov Ceg Ntawm RGB LED Ua

Coj koj RGB LED thiab saib ntawm ob txhais ceg, koj yuav pom tias ib txhais ceg ntev dua txhua qhov. Taw qhia cov LED kom cov ceg ntev tshaj plaws no nyob rau sab laug.

Pin 1 yog siv los ua LED ci RED

Pin 2 yog tus pin hauv av

Tus Pin 3 ua rau LED ci GREEN

Tus Pin 4 ua rau LED ci BLUE

RGB LED Kuv tab tom siv muaj cov cathode ib txwm, uas txhais tau tias koj txuas nws cov ceg hauv av rau Raspberry Pi hauv av pin kom nws ua haujlwm.

Kauj Ruam 3: Ntxig rau 330 Ohm Resistors thiab Ground Jumper Cable rau hauv Breadboard

Ntxig rau 330 Ohm Resistors thiab Ground Jumper Cable rau hauv Breadboard
Ntxig rau 330 Ohm Resistors thiab Ground Jumper Cable rau hauv Breadboard

Txhawm rau ua kom yooj yim pom ntawm daim duab peb tuaj yeem tso cov resistors thiab cov kab hauv av uas lawv xav tau ua ntej. Resistors tsis muaj polarity yog li nws tsis muaj teeb meem dab tsi puag ncig lawv mus.

Nco tseg: Vim li cas peb thiaj xav tau peb tus tiv thaiv rau ib qho LED?

Xav txog RGB LED ua 3 qhov sib txawv LEDs tau ntim rau hauv ib qho. Yog tias peb muaj 3 tus tib neeg LEDs hauv Circuit peb yuav siv tus tiv thaiv rau txhua tus, thiab yog li peb xav tau tus tiv thaiv rau txhua ceg xim ntawm RGB LED.

Kauj Ruam 4: Ntxiv LED rau Peb Lub Circuit Court

Ntxiv LED rau Peb Lub Vaj Tsev
Ntxiv LED rau Peb Lub Vaj Tsev
Ntxiv LED rau Peb Lub Vaj Tsev
Ntxiv LED rau Peb Lub Vaj Tsev

Tam sim no peb muaj cov tiv thaiv thiab cov kab hauv av nyob hauv qhov chaw, peb tuaj yeem txhim kho peb cov LED rau hauv daim phiaj ci ci. Taw qhia LED yog li cov ceg ntev tshaj plaws yog sab laug.

Maj mam muab ob txhais ceg me ntsis tso cai rau lawv ntsaws rau hauv lub khob cij, ua kom ntseeg tau tias txhua ceg yog nyob rau tib txoj kab raws li tus tiv thaiv sib xws.

Cov ceg ntev tshaj plaws (ceg 2) yuav tsum ua kab nrog cov kab hauv av dub.

Kauj Ruam 5: Txuas Cables rau Breadboard Tshooj 1: Txuas Hauv av

Txuas cov Cables rau Breadboard Tshooj 1: Txuas Hauv av
Txuas cov Cables rau Breadboard Tshooj 1: Txuas Hauv av
Txuas cov Cables rau Breadboard Tshooj 1: Txuas Hauv av
Txuas cov Cables rau Breadboard Tshooj 1: Txuas Hauv av
Txuas cov Cables rau Breadboard Tshooj 1: Txuas Hauv av
Txuas cov Cables rau Breadboard Tshooj 1: Txuas Hauv av

Ua ntej no peb txuas hauv av los ntawm Raspberry Pi mus rau hauv av ceg ntawm LED.

Hauv kuv daim duab kuv tau txuas tus txiv neej/poj niam cable los ntawm tus pin 6 ntawm Raspberry GPIO mus rau hauv av tsheb nqaj hlau ntawm lub khob cij los txuas LED lub hauv paus ceg mus rau Raspberry Pi.

Daim npav siv qhia koj tus pin teeb tsa rau Raspberry Pi GPIO. 40 tus pin GPIO rau sab xis ntawm daim duab yog rau Raspberry Pi 2, uas kuv siv los ua txoj haujlwm no.

Kauj Ruam 6: Txuas Cov Cables rau Breadboard Ntu 2: Txuas Txuas Liab LED Taw

Txuas cov Cables rau Breadboard Ntu 2: Txuas Txuas Liab LED Ceg
Txuas cov Cables rau Breadboard Ntu 2: Txuas Txuas Liab LED Ceg
Txuas cov Cables rau Breadboard Ntu 2: Txuas Txuas Liab LED Ceg
Txuas cov Cables rau Breadboard Ntu 2: Txuas Txuas Liab LED Ceg
Txuas cov Cables rau Breadboard Ntu 2: Txuas Txuas Liab LED Ceg
Txuas cov Cables rau Breadboard Ntu 2: Txuas Txuas Liab LED Ceg

Thawb tus txiv neej kawg ntawm txoj hlua mus rau hauv lub qhov tsuas yog siab dua tus tiv thaiv ntawm sab laug, thiab thawb tus poj niam kawg ntawm txoj hlua mus rau GPIO17 (pin11) ntawm Raspberry Pi.

Daim npav siv rau tus pin GPIO yuav pab coj koj mus rau tus pin raug.

Kauj Ruam 7: Txuas Cables mus rau Breadboard Ntu 3: Txuas Ntsuab LED Taw

Txuas cov Cables rau Breadboard Ntu 3: Txuas Green LED Leg
Txuas cov Cables rau Breadboard Ntu 3: Txuas Green LED Leg
Txuas cov Cables rau Breadboard Ntu 3: Txuas Green LED Leg
Txuas cov Cables rau Breadboard Ntu 3: Txuas Green LED Leg
Txuas cov Cables rau Breadboard Ntu 3: Txuas Green LED Leg
Txuas cov Cables rau Breadboard Ntu 3: Txuas Green LED Leg

Thawb tus txiv neej kawg ntawm txoj hlua mus rau hauv lub qhov tsuas yog siab dua tus tiv thaiv nyob hauv nruab nrab, thiab thawb tus poj niam kawg ntawm txoj hlua mus rau GPIO18 (pin12) ntawm Raspberry Pi.

Daim npav siv rau tus pin GPIO yuav pab coj koj mus rau tus pin raug.

Kauj Ruam 8: Txuas Cables rau Breadboard Tshooj 4: Txuas Blue LED Leg

Txuas cov Cables rau Breadboard Tshooj 4: Txuas Blue LED Leg
Txuas cov Cables rau Breadboard Tshooj 4: Txuas Blue LED Leg
Txuas cov Cables rau Breadboard Tshooj 4: Txuas Blue LED Leg
Txuas cov Cables rau Breadboard Tshooj 4: Txuas Blue LED Leg
Txuas cov Cables rau Breadboard Tshooj 4: Txuas Blue LED Leg
Txuas cov Cables rau Breadboard Tshooj 4: Txuas Blue LED Leg
Txuas cov Cables rau Breadboard Tshooj 4: Txuas Blue LED Leg
Txuas cov Cables rau Breadboard Tshooj 4: Txuas Blue LED Leg

Thawb tus txiv neej kawg ntawm txoj hlua mus rau hauv lub qhov tsuas yog siab dua tus tiv thaiv ntawm sab xis, thiab thawb tus poj niam kawg ntawm txoj hlua mus rau GPIO27 (pin13) ntawm Raspberry Pi.

Daim npav siv rau tus pin GPIO yuav pab coj koj mus rau tus pin raug.

Kauj Ruam 9: Lub cajmeem hauv Kos: Txheeb Xyuas Circuit

Programming in Scratch: Tshawb Xyuas Circuit
Programming in Scratch: Tshawb Xyuas Circuit
Programming in Scratch: Tshawb Xyuas Circuit
Programming in Scratch: Tshawb Xyuas Circuit
Programming in Scratch: Tshawb Xyuas Circuit
Programming in Scratch: Tshawb Xyuas Circuit

Thaum kuv thawj zaug teeb tsa txoj haujlwm no kuv tau ua tsis zoo me me thiab sib xyaw kuv cov xim xim, uas txhais tau tias thaum kuv xav kom liab tuaj, ntsuab tuaj ntxiv, yog li kuv tau sau qhov program yooj yim los txheeb xyuas tias txhua yam tau txuas nrog kom raug.

Kev ntsuas LED yog tswj los ntawm 3 khub tus yuam sij

A thiab Z tswj RED, A hloov liab rau, Z hloov liab liab

S thiab X tswj GREEN, S hloov ntsuab rau, X hloov ntsuab tawm

D thiab C tswj BLUE, D hloov xiav rau, C hloov xiav tawm

Teeb tus pin kom siab ua rau lub teeb ci LED, teeb tsa nws kom qis hloov LED tawm.

Rub tawm qhov program thiab ntsuas koj lub Circuit yog tias koj xav kom ntseeg tau tias nws tau txuas nrog kom raug.

Kauj ruam 10: Programming hauv Kos: Kuv Yuav Ua Li Cas Nrog RGB LED

Programming hauv Kos: Kuv Yuav Ua Li Cas Nrog RGB LED
Programming hauv Kos: Kuv Yuav Ua Li Cas Nrog RGB LED

Kev ua haujlwm hauv kos yog qhov kev paub zoo. Nws muaj qhov nyem thiab luag interface thiab zoo nkauj heev. Txawm hais tias nws tau tsim thawj zaug los qhia rau menyuam yaus rau kev ua haujlwm kuv yeej xav tias nws yog qhov chaw zoo tsim muaj txiaj ntsig ib puag ncig raws li kuv xav tau qhia hauv cov cai uas tswj hwm LED hauv kuv txoj haujlwm.

Yog li ntawm no yog qhov kuv xav kom tshwm sim:

Kev hloov xim yuav ua tiav hauv peb theem:

Hauv thawj theem peb pib nrog liab ntawm qhov siab tshaj plaws thiab ntsuab thiab xiav teeb mus rau qib me me.

Peb tom qab ntawd pib txo qis lub teeb liab los ntawm -1, thaum nce ntsuab ci ntawm 1.

Peb siv lub voj voos ntsuas kom txwv pes tsawg zaus qhov no tshwm sim.

Thaum lub voj ntsuas tau mus txog 255 peb pib theem thib ob.

Hauv theem thib ob ntsuab yuav yog qhov siab tshaj plaws, liab thiab xiav teeb rau qib qis.

Peb txo qhov ci ci ntsuab los ntawm -1 thaum ua kom lub ntsej muag ci ntsa iab los ntawm 1.

Peb lub voj voj rau theem thib ob tau teeb tsa rau 509.

Thaum nws mus txog 509 peb yuav pib theem 3.

Hauv theem peb, xiav yog qhov ci tshaj plaws thiab ntsuab thiab liab yog nyob qis.

Peb pib qis qis ci ci los ntawm -1 thaum nce lub teeb liab los ntawm 1.

Thaum lub voj ntsuas mus txog 763, lub voj voog yuav pib dua ntawm theem 1.

Peb muaj peb qhov sib txawv redVal, greenVal thiab blueVal los tuav qhov tseem ceeb ntawm txhua xim qib ci ntsa iab thiab cov txiaj ntsig no tom qab ntawd xa tawm mus rau qhov tseeb GPIO pins rau lub zog rau ob txhais ceg ntawm LEDs los teeb tsa txhua qhov xim qhov ci ci, uas nyob rau hauv lem muab rau peb xim sib tov peb xav tau.

Thiab qhov ntawd yog kuv qhov kev sim hla dhau cov xim siv lub RGB LED thiab kos.

Yog tias koj muaj Arduino thiab koj tau siv daim duab kos kuv txuas uas tau tshoov kuv siab kom sau Scratch version, koj yuav pom tias tsis muaj xim flickering txhua. Kuv tsis paub tseeb vim li cas Scratch version flickers ntau heev. Kuv xav tias Arduino zoo dua ntawm kev tuav PWM, tab sis yog tias koj pom qee yam hauv kuv cov cai uas xav tau txhim kho, Kuv yuav zoo siab heev yog tias koj siv sijhawm los qhia rau kuv.

Ua tsaug rau koj nyeem kuv cov ntawv qhia thiab kuv vam tias koj muaj hnub zoo!

Kauj Ruam 11: Txheeb Screen ntawm Scratch Program

Screen Capture ntawm Scratch Program
Screen Capture ntawm Scratch Program

Yog tias koj xav kom muaj kev mus ntawm lub cajmeem nws tus kheej ntawm no yog saib ze ntawm cov txheej txheem.

Pom zoo: