Cov txheej txheem:

Arduino RGB LED Sawb Controller: 4 Cov Kauj Ruam
Arduino RGB LED Sawb Controller: 4 Cov Kauj Ruam

Video: Arduino RGB LED Sawb Controller: 4 Cov Kauj Ruam

Video: Arduino RGB LED Sawb Controller: 4 Cov Kauj Ruam
Video: how to make humidifier at home | DIY ultrasonic mist maker!! 2024, Kaum ib hlis
Anonim
Arduino RGB LED Sawb Controller
Arduino RGB LED Sawb Controller

Feem ntau thaum tib neeg xav tswj lawv cov RGB LED sawb nrog Arduino, peb lub zog ntsuas tau siv los sib xyaw xim liab, ntsuab thiab xiav. Qhov no ua haujlwm thiab tuaj yeem ua tiav zoo rau koj cov kev xav tau, tab sis kuv xav ua qee yam kom nkag siab zoo dua, qee yam zoo li lub log xim.

Txoj haujlwm no zoo li yog daim ntawv thov zoo tshaj plaws rau tus lej nkag teb chaws. Nov yog lub cuab yeej uas hloov cov lus tsa suab ntawm nws cov ncej mus rau cov khoom siv digital. Thaum lub taub hau tig, tus xa ntawv xa tawm lub teeb liab (mem tes) uas tuaj yeem ntsuas los ntawm Arduino. Yog xav paub ntau ntxiv txog cov teb encoders, koj tuaj yeem saib cov vis dis aus no uas piav qhia nws ntau zuj zus.

Hauv Cov Lus Qhia no kuv yuav qhia koj yuav ua li cas thiaj ua tau Arduino RGB LED sawb tswj los ntawm kev siv lub cav nkag teb chaws. Cov lus qhia no suav nrog kev tsim cov phiaj xwm hluav taws xob ntawm lub khob cij. Txawm li cas los xij koj tuaj yeem tsim koj tus kheej PCB thiaj li tsim tau daim thaiv npog Arduino!

Kauj Ruam 1: Qhov Chaw

Qhov
Qhov
Qhov
Qhov

Rau RGB LED sawb tswj koj yuav xav tau cov ntaub ntawv hauv qab no:

  • 1 x Arduino Nano
  • 3x IRLB8721PBF, ib qho N-channel logic qib MOSFET yuav ua ntev npaum li nws tau ntsuas qis kawg ntawm 12V thiab tam sim no koj cov hlua LED tau siv.
  • 1 x Rotary encoder
  • 1x 12V 2A fais fab mov, tam sim no lub zog xa khoom yuav tsum xa tuaj yuav nyob ntawm qhov ntev ntawm kev siv LED sawb.
  • 16x Txiv neej rau txiv neej jumper xov hlau
  • 1x Solderless breadboard, txhua lub khob cij yuav ua ntev npaum li nws loj txaus.

Kauj ruam 2: Circuit Court

Circuit Court
Circuit Court
Circuit Court
Circuit Court

Txuas Arduino mus rau 12V thiab GND txoj kev tsheb nqaj hlau. Tom qab ntawd txuas rau lwm qhov raws li hauv qab no:

Teb encoder

Pin A - D4

Pin B - D3

GND - NCO

MOSFET Liab

Rooj vag - GND

Ntws - LED sawb liab hlau

Tau qhov twg los - D11

MOSFET GreenGate - GND

Ntws - LED sawb ntsuab xaim

Tau qhov twg los - D9

MOSFET BlueGate - GND

Ntws - LED sawb xiav hlau

Tau qhov twg los - D6

Kauj ruam 3: Code

// Arduino PWM pin

int redPin = 11; int greenPin = 6; int bluePin = 9; // Arduino encoder pins int encoderPinA = 3; int encoderPinB = 4; // Xim hloov xim int colorVal; koj redVal; koj greenVal; koj blueVal; // Encoder hloov pauv int encoderPos; int encoderPinACurrent; int encoderPinALast = HIGH; // Lwm int txee; teeb tsa tsis muaj dab tsi () {pinMode (encoderPinA, INPUT_PULLUP); pinMode (encoderPinB, INPUT_PULLUP); } void loop () {readEncoder (); encoder2rgb (txee); analogWrite (redPin, redVal); analogWrite (greenPin, ntsuabVal); analogWrite (bluePin, blueVal); } int readEncoder () {encoderPinACurrent = digitalRead (encoderPinA); yog ((encoderPinALast == LOW) && (encoderPinACurrent == HIGH)) {yog (digitalRead (encoderPinB) == LOW) {encoderPos = encoderPos - 1; } lwm {encoderPos = encoderPos + 1; }} encoderPinALast = encoderPinACurrent; txee = encoderPos*8; yog (txee 1535) {txee = 0; } rov qab txee; } int encoder2rgb (int counterVal) {// Liab rau daj yog (counterVal <= 255) {colorVal = counterVal; redVal = 255; ntsuabVal = colorVal; blueVal = 0; } // Daj rau ntsuab dua yog tias (counterVal <= 511) {colorVal = counterVal - 256; redVal = 255 - colorVal; greenVal = 255; blueVal = 0; } // Ntsuab mus rau lwm yam xim yog (counterVal <= 767) {colorVal = counterVal - 512; redVal = 0; greenVal = 255; blueVal = ximVal; } // Cyan rau xiav lwm tus yog (counterVal <= 1023) {colorVal = counterVal - 768; redVal = 0; ntsuabVal = 255 - colorVal; blueVal = 255; } // Xiav rau magenta lwm yog (counterVal <= 1279) {colorVal = counterVal - 1024; redVal = ximVal; ntsuabVal = 0; blueVal = 255; } // Magenta rau liab ntxiv {colorVal = counterVal - 1280; redVal = 255; ntsuabVal = 0; blueVal = 255 - colorVal; } rov redVal, ntsuabVal, blueVal; }

Pom zoo: