byte valR;
byte valG;
byte valB;
void setup() {
pinMode(A1, INPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
Serial.begin(115200);
}
void loop() {
int val = analogRead(A1);
if (val < 341) {
valR = map(val, 0, 341, 255, 0);
valG = map(val, 0, 341, 0, 255);
valB = 0;
}
if ((val > 341) && (val < 682)) {
valG = map(val, 341, 682, 255, 0);
valB = map(val, 341, 682, 0, 255);
valR = 0;
}
if (val > 682) {
valB = map(val, 682, 1023, 255, 0);
valR = map(val, 682, 1023, 0, 255);
valG = 0;
}
analogWrite(3, valR);
analogWrite(4, valG);
analogWrite(5, valB);
Serial.println(valR);
}