// RGB and R, G, B LED demo
const int pinR = 23;
const int pinG = 22;
const int pinB = 21;
const int potR = 34;//Analog ADC1_CH6
const int potG = 35;//Analog ADC1_CH7
const int potB = 32;//Analog ADC1_CH4
void setup() {
pinMode(pinR, OUTPUT);
pinMode(pinG, OUTPUT);
pinMode(pinB, OUTPUT);
pinMode(potR, INPUT);
pinMode(potG, INPUT);
pinMode(potB, INPUT);
}
int readPot(int pin) {
//map(value, fromLow, fromHigh, toLow, toHigh)
return map(analogRead(pin), 0, 1023, 0, 255);
}
void loop() {
analogWrite(pinR, readPot(potR));
analogWrite(pinG, readPot(potG));
analogWrite(pinB, readPot(potB));
}