Eine RGB-LED wird von drei Potentiometern kontrolliert.
/*
* RGB_LEDs sketch
* for RGB-LEDs with 6 pins (common cathode)
* RGB LEDs driven from potis
*/
int redPin = 3; // choose pins for each of the LED's colors
int bluePin = 5;
int bluePin2 = 6;
int greenPin = 9;
int potiR = 3; // choose pins for potis
int potiG = 4;
int potiB = 5;
int valR, valG, valB;
void setup() {
Serial.begin(9600); // initialize serial interface
}
void loop() {
// read values from potis and map them to a range of 0-255
int valR = map(analogRead(potiR), 0, 1023, 0, 255);
int valG = map(analogRead(potiG), 0, 1023, 0, 255);
int valB = map(analogRead(potiB), 0, 1023, 0, 255);
// write the RGB values to the pins
analogWrite(redPin, valR);
analogWrite(greenPin, valG);
analogWrite(bluePin, valB);
analogWrite(bluePin2, valB);
/*
// print information to Serial Monitor
Serial.print("R: ");
Serial.print(valR);
Serial.print("\t");
Serial.print("G: ");
Serial.print(valG);
Serial.print("\t");
Serial.print("B: ");
Serial.println(valB);
*/
}
