int redPin = 11;// R – digital 9
int greenPin = 10;// G – digital 10
int bluePin = 9;// B – digital 11
int potPin = 0;// potentiometer 1 – analogue 0
int buttonPin = 1;
int buttonStatus = 3;
int potValue;
void setup(){
pinMode(redPin,OUTPUT);
pinMode(greenPin,OUTPUT);
pinMode(bluePin,OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop(){
int state = digitalRead(buttonPin);
if (state == LOW){
if (buttonStatus < 3){
buttonStatus=buttonStatus + 1;
}
else{
buttonStatus = 1;
}
}
switch (buttonStatus){
case 1:
potValue = analogRead(potPin);
potValue = map(potValue,0,1023,0,255);
analogWrite(redPin,constrain(potValue,0,255));
break;
case 2:
potValue = analogRead(potPin);
potValue = map(potValue,0,1023,0,255);
analogWrite(greenPin,constrain(potValue,0,255));
break;
case 3:
potValue = analogRead(potPin);
potValue = map(potValue,0,1023,0,255);
analogWrite(bluePin,constrain(potValue,0,255));
break;
}
}