int channel = 0;
//R = 0
//G = 1
//B = 2
int pinR = 9;
int pinG = 10;
int pinB = 11;
int pinT = 4;
bool hasPressed = false;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(pinR, OUTPUT);
pinMode(pinG, OUTPUT);
pinMode(pinB, OUTPUT);
pinMode(pinT,INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
int potValue = analogRead(A0);
float percent = potValue / 1023.0;
if(channel==0) {
analogWrite(pinR, 255*percent);
} else if(channel==1) {
analogWrite(pinG, 255*percent);
} else if(channel==2) {
analogWrite(pinB, 255*percent);
}
if(digitalRead(pinT)==LOW) {
if(hasPressed==false) {
hasPressed = true;
channel = channel + 1;
if(channel>2) {
channel = 0;
}
}
} else {
hasPressed = false;
}
}