Aici va voi prezenta cum puteti controla un LED RGB cu o placuta Arduino Duemilanove si cu 3 potentiometre:
COD:
const int redpin = 9;
const int greenpin = 10;
const int bluepin = 11;
const int redpotpin = 0;
const int greenpotpin = 1;
const int bluepotpin = 2;
int currentcolorvaluered;
int currentcolorvaluegreen;
int currentcolorvalueblue;
void setup()
{
pinMode(redpin, OUTPUT);
pinMode(greenpin, OUTPUT);
pinMode(bluepin, OUTPUT);
}
void loop()
{
currentcolorvaluered = (255 - (analogRead(redpotpin) / 4));
currentcolorvaluegreen = (255 - (analogRead(greenpotpin) / 4));
currentcolorvalueblue = (255 - (analogRead(bluepotpin) / 4));
analogWrite(redpin, currentcolorvaluered);
analogWrite(greenpin, currentcolorvaluegreen);
analogWrite(bluepin, currentcolorvalueblue);
}
Pinii de la LED-ul RGB trebuie sa fie conectati la pini PWM, si este bine sa puneti la fiecare pin al LED-ului(cathode) o rezistenta de 220 Ohmi.
Abonați-vă la:
Postare comentarii (Atom)
Niciun comentariu:
Trimiteți un comentariu