const int pot1 = A0;
const int pot2 = A1;
const int pot3 = A2;
const int red = 3;
const int green = 5;
const int blue = 6;
// connect the long of the led (comm) to 5 v, the rest to the ~ ones
void setup() {
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(pot1, INPUT);
pinMode(pot2, INPUT);
pinMode(pot3, INPUT);
}
// potentiometer all gnd to the same gnd
int readPot(int pin) {
return map(analogRead(pin), 0, 1023, 0, 255);
}
// subtract from the maximum for colours
void loop() {
analogWrite(red, 255-readPot(pot1));
delay(1000);
analogWrite(green, 255-readPot(pot2));
delay(1000);
analogWrite(blue, 255-readPot(pot3));
delay(1000);
analogWrite(red, 1023-readPot(pot1));
}